【发布时间】:2019-09-20 04:26:48
【问题描述】:
我正在尝试为重新请求发布方法执行 AddBody。我正在使用 RestSharp 版本 104.XXX,它没有 addJsonBody 像版本 105.XXXX 一样,因为我的应用程序面临其他问题。所以我坚持使用版本 104,在此过程中我无法使用 addBody 并发送序列化的 json,每次我使用下面的代码时,我都会得到 . "error":"Unsupported Media Type","message":"Content type 'text/xml;charset=UTF-8' not supported".. 有没有人遇到过这个问题并想出了使用旧版本 RestSharp 的方法。 .
var restRequest = new RestRequest(Method.POST);
restRequest.AddHeader("authorization", "Bearer " + token);
restRequest.AddHeader("source", "M");
restRequest.AddHeader("content-type", "application/json");
restRequest.AddBody(JsonConvert.SerializeObject(requestObj, this.jsonSettings));
【问题讨论】:
-
试试
restRequest.AddParameter("application/json", JsonConvert.SerializeObject(requestObj, this.jsonSettings), ParameterType.RequestBody);,看看有什么不同。 -
@dvo 太棒了谢谢你.. 快速添加比作为答案,这样我就可以接受正确的答案..
标签: c#