多部分/混合请求在RestSharp中不起作用

时间:2019-07-02 14:33:55

标签: c# restsharp

我需要发送 multipart / mixed 请求以执行某些操作,并且端点支持 multipart / mixed 内容类型,该内容类型支持application / json和application / xml。

>

当我尝试使用Restsharp如下发送请求时,内容类型在提琴手中以Content-Type: multipart/form-data; boundary=-----------------------------28947758029299的形式传递,并以415 -UNSUPPORTED MEDIA TYPE的形式得到响应

代码:

RestRequest req = new RestRequest(endpoint, Method.POST)
{
    AlwaysMultipartFormData = true
};

if (!string.IsNullOrEmpty(bearerToken))
{
    req.AddHeader("Authorization", string.Format("Bearer {0}", bearerToken));
}

req.AddHeader("Content-Type", "mulitpart/mixed");

req.AddHeader("Content-Type", "application/json");
req.AddParameter("processTypeCreationMetadata", "<JSON Request>");
req.AddHeader("Content-Type", "application/xml");
req.AddParameter("processBpmnDefinition", <xml Request Content>);

var res = _client.Execute(req);
return res.Content;

0 个答案:

没有答案