Restsharp vs Postman - content-type 视频
Restsharp vs Postman - content-type for a video
为了测试我们的一个 API 端点,我需要上传一个视频。我们的测试框架使用 RestSharp。
该调用与 Postman 一起使用,它生成以下相关 headers 和 body:
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 请求?
找到了,答案是:
restRequest.AlwaysMultipartFormData = true;
restRequest.AddFile(request.FileName, request.FullPath, "video/mp4");
为了测试我们的一个 API 端点,我需要上传一个视频。我们的测试框架使用 RestSharp。
该调用与 Postman 一起使用,它生成以下相关 headers 和 body:
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 请求?
找到了,答案是:
restRequest.AlwaysMultipartFormData = true;
restRequest.AddFile(request.FileName, request.FullPath, "video/mp4");