Tôi đang tạo RestSharp.RestRequest qua:RestSharp có ghi đè lên Loại nội dung được đặt theo cách thủ công không?
RestRequest request = new RestRequest();
request.Method = Method.POST;
request.Resource = "/rest-uri";
request.AddHeader("Content-Type", "application/someContentType");
string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + Environment.NewLine +
"<register-request">" + Environment.NewLine +
" <name=\"someName\"/>" + Environment.NewLine +
"</register-request>");
request.AddParameter("text/xml", registerSinkRequest, ParameterType.RequestBody);
(Các Content-Type là tự thiết để application/someContentType
)
Trong debug mode nó cũng cho thấy Content-Type=application/someContentType
Nhưng thực hiện các RestRequest trả về một 415 Media Not Supported
-Lỗi và WireShark cho thấy rằng Loại phương tiện được đặt thành text/xml
(như được đặt trong phương pháp AddParameter).
Tại sao RestSharp hiển thị Loại nội dung khác thì WireShark? Và làm thế nào tôi có thể ngăn chặn Content-Type được thay đổi (nếu nó là)?
Vậy tại sao bạn không sử dụng 'application/someContentType' trong' AddParameter() '? – svick