在CURL中设置多部分/混合请求的一部分的内容类型 [英] Set content type of part of multipart/mixed request in CURL

查看:97
本文介绍了在CURL中设置多部分/混合请求的一部分的内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个http请求中发送json请求和几个文件。我正在为此使用 multipart / mixed 请求

I want to send json request and several files in one http request. I'm using multipart/mixed request for that

curl -H "Content-Type: multipart/mixed" -F "request=@body.json; type=application/json" -F "file1=@2.xml" -F "file2=@2.pdf" -X POST hostName

请求字段具有 application / json 内容类型,并根据该指示,我将这部分定义为json请求,而其他部分是文件。

request field has application/json content type and by that indication I define that this part is json request and other parts are files.

我的问题是如何内联请求主体在curl请求中。我尝试使用

My question is how to inline request body in curl request. I try to use

curl -H "Content-Type: multipart/mixed" -F "request={"param1": "value1"}" -F "file1=@2.xml" -F "file2=@2.pdf" -X POST hostName

,但请求的内容类型将为纯文本/文本

推荐答案

您可以在分号后添加内容类型信息:

You can add content-type information after semicolon:

curl -H "Content-Type: multipart/mixed" -F "request={"param1": "value1"};type=application/json"

这篇关于在CURL中设置多部分/混合请求的一部分的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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