使用Postman Chrome扩展程序发送多部分/混合内容 [英] Sending multipart/mixed content with Postman Chrome extension

查看:1173
本文介绍了使用Postman Chrome扩展程序发送多部分/混合内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Postman Chrome扩展程序创建POST多部分/混合请求时遇到困难

I'm struggling with creating POST multipart/mixed request with Postman Chrome extension

这是我的curl请求,效果不错

Here is my curl request what works nice

curl -H "Content-Type: multipart/mixed" 
-F "metadata=@simple_json.json; type=application/json "
-F "content=@1.jpg; type=image/jpg" -X POST http://my/api/item -i -v

有趣的部分回应


Content-Length:41557

Content-Length: 41557

预期:100-继续

Content-Type:multipart / mixed; boundary = ---------------------------- 8aaca457e117

Content-Type: multipart/mixed; boundary=----------------------------8aaca457e117


  • 其他资料不够精细transfer.c:1037:0 0

  • HTTP 1.1或更高版本与持续连接,支持流水线

当我使用Postman

And when I use Postman

我收到这样的回复

{"message":"Could not parse multipart servlet request;
 nested exception is org.apache.commons.fileupload.FileUploadException: 
 the request was rejected because no multipart boundary was     
 found","type":"error","status":500,"requestId":"1861eloo6fpio"}

就是这样 - 我想摆脱那个错误。
如果需要更多信息,请问:

That's it - I wish to get rid of that error. If some more information needed please ask :)

推荐答案

简短的答案:从您的Postman请求中删除 Content-Type 标题。

I was facing this problem too. Short answer: remove the Content-Type header from your Postman request.

对于多部分请求,c $ c> Content-Type 应该是相当特殊的 - 它应该看起来像这样:

The long story is that the Content-Type for a multipart request should be rather special -- it should look kind of like this:

multipart/form-data; boundary=----WebKitFormBoundaryzeZR8KqAYJyI2jPL

问题是边界很重要,需要正确与用于分隔正在上传的文件的边界匹配。解决方案很简单:不要指定 Content-Type !当您上传文件时,Postman将自动为您添加上述内容类型,除了边界将填充任何Postman或Chrome用于分隔多部分内容。

The problem is that the boundary is important and it needs to exactly match the boundary used to separate the files being uploaded. The solution is simple: do not specify a Content-Type! When you upload files, Postman will automatically append the above content type for you, except the boundary will be filled in with whatever Postman or Chrome is using to separate the multipart content.

您可以使用Chrome开发人员工具(在Postman中)检查 Content-Type 标头,以及 Content- Disposition 多部分数据的头部,这也是手动构造(在Postman中不可能)的痛苦。

You can verify this behavior by using Chrome developer tools (within Postman) to examine the Content-Type header being added, in addition to the Content-Disposition headers of the multipart data, which are also a pain to construct manually (and impossible within Postman).

strong>:我的答案是为那些需要一个 multipart / form-data 答案的解决方案。 OP正在寻找一个 multipart / mixed 解决方案。我的回答在这种情况下是不够的。话虽这么说,似乎很多人只是想要 multipart / form-data 解决方案,所以我会在这里留下我的回答。

Note: My answer is a solution for those who need a multipart/form-data answer. The OP was looking for a multipart/mixed solution. My answer will not suffice in this scenario. That being said, it seems a lot of people just want the multipart/form-data solution, so I will leave my answer here.

这篇关于使用Postman Chrome扩展程序发送多部分/混合内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆