我正在通过以下方式创建 RestSharp.RestRequest:
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);
(Content-Type 手动设置为application/someContentType
)
在调试模式下,它还显示Content-Type=application/someContentType
但是执行 RestRequest 返回一个 -Error415 Media Not Supported
并且 WireShark 显示 Media-Type 设置为text/xml
(如在 AddParameter-Method 中设置)。
为什么 RestSharp 显示的 Content-Type 与 WireShark 不同?以及如何防止 Content-Type 被更改(如果是)?