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

查看:24
本文介绍了使用 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

回复中有趣的部分

内容长度:41557

期望:100-继续

内容类型:多部分/混合;边界=----------------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.

长话短说,多部分请求的 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.

除了 Content-Disposition 标头之外,您可以使用 Chrome 开发人员工具(在 Postman 中)检查正在添加的 Content-Type 标头来验证此行为多部分数据,手动构建也很痛苦(在 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).

注意:我的答案是为那些需要 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天全站免登陆