使用带有承载令牌的RestClient时获取StatusCode:UnsupportedMediaType

时间:2019-09-09 14:00:07

标签: c# rest rest-client

获取StatusCode:UnsupportedMediaType用于文件上传。我正在使用带有承载令牌的RestClient

我成功获得了承载令牌,但是当将JSON发送到API时,却​​得到了不受支持的异常媒体类型

var client = new RestClient(requestAPIURL); 

var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");

request.AddHeader("Authorization", string.Format("Bearer " + 
token.AccessToken));
request.AddParameter("application/json", 

JsonConvert.SerializeObject(jsonData), ParameterType.RequestBody);

var response = client.Execute(request);

1 个答案:

答案 0 :(得分:0)

POST在请求正文中的JSON

request.AddBody(JsonConvert.SerializeObject(jsonData));