Restsharp vs Postman-视频的内容类型
为了测试我们的一个API端点,我需要上传一个视频。我们的测试框架使用RestSharp 该调用与Postman一起工作,后者生成以下相关标题和正文:Restsharp vs Postman-视频的内容类型,postman,restsharp,Postman,Restsharp,为了测试我们的一个API端点,我需要上传一个视频。我们的测试框架使用RestSharp 该调用与Postman一起工作,后者生成以下相关标题和正文: Content-Type: multipart/form-data; boundary=--------------------------285414664033564173408812 Accept: */* content-length: 1055942 ----------------------------28541466403356
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);
是否可以像邮递员请求一样构造RestSharp请求?找到它,答案是:
restRequest.AlwaysMultipartFormData = true;
restRequest.AddFile(request.FileName, request.FullPath, "video/mp4");