【问题标题】:Restsharp vs Postman - content-type for a videoRestsharp vs Postman - 视频的内​​容类型
【发布时间】:2018-05-17 17:51:37
【问题描述】:

为了测试我们的一个 API 端点,我需要上传一个视频。我们的测试框架使用 RestSharp。

该调用与 Postman 一起使用,它会生成以下相关的标头和正文:

Content-Type: multipart/form-data; boundary=--------------------------285414664033564173408812
Accept: */* 
content-length: 1055942

----------------------------285414664033564173408812
Content-Disposition: form-data; name=""; filename="uservideo.mp4"
Content-Type: video/mp4  
// binary data here

现在,当使用 RestSharp 尝试相同的操作时,请求的构造如下,但它失败了:

Accept: application/json
Content-Type: multipart/form-data; boundary=-----------------------------28947758029299
Content-Length: 1055956

-------------------------------28947758029299
Content-Disposition: form-data; name="uservideoTest"; filename="uservideo.mp4"
Content-Type: application/octet-stream
// binary data here

使用的代码如下:

restRequest.AlwaysMultipartFormData = true;
restRequest.AddFile(request.FileName, request.FullPath);

是否可以像 Postman 请求一样构造 RestSharp 请求?

【问题讨论】:

    标签: postman restsharp


    【解决方案1】:

    找到了,答案是:

    restRequest.AlwaysMultipartFormData = true;
    restRequest.AddFile(request.FileName, request.FullPath, "video/mp4");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 2013-06-06
      • 2014-03-17
      • 1970-01-01
      • 2018-10-27
      相关资源
      最近更新 更多