我正在尝试将下面的curl请求转换为postman工具的HTTP请求。 postman 工具在这个问题中可能并不重要。请告诉我如何将curl 转换为http。
curl -X POST -i 'https://a-webservice.com' -H X-apiKey:jamesBond007 -d MESSAGE-TYPE="pub.controller.user.created" -d PAYLOAD='a json object goes here!'
我尝试/学到的东西: - 设置 header 内容类型:json/application, X-apiKey
- 从curl文档来看,-d选项意味着我们需要设置content-type application/x-www-form-urlencoded
Postman 允许我仅使用 4 个选项中的 1 个来设置请求正文:form-data、x-www-form-urlencoded、raw、binary。你能展示如何将curl的两个-d选项转换为这些选项吗?
我很困惑如何将它们组合在一起。
谢谢!
最佳答案
application/x-www-form-urlencoded
数据的格式与查询字符串相同,因此:
MESSAGE-TYPE=pub.controller.user.created&PAYLOAD=a json object goes here!
为了确认,您可以使用 curl
本身转储请求数据,使用 the --trace-ascii
option :
curl --trace-ascii - -X POST -i 'https://a-webservice.com' \
-H X-apiKey:jamesBond007 -d MESSAGE-TYPE="pub.controller.user.created" \
-d PAYLOAD='a json object goes here!'
--trace-ascii
接受文件名作为参数,但如果您给它 -
,它将转储到 stdout
。
上述调用的输出将包括如下内容:
=> Send header, 168 bytes (0xa8)
0000: POST / HTTP/1.1
0011: Host: example.com
0024: User-Agent: curl/7.51.0
003d: Accept: */*
004a: X-apiKey:jamesBond007
0061: Content-Length: 73
0075: Content-Type: application/x-www-form-urlencoded
00a6:
=> Send data, 73 bytes (0x49)
0000: MESSAGE-TYPE=pub.controller.user.created&PAYLOAD=a json object g
0040: oes here!
== Info: upload completely sent off: 73 out of 73 bytes
所以与 Convert curl request into http request? 的答案中确认的内容相同使用 nc
,但确认仅使用 curl
本身以及 --trace-ascii
选项。
关于linux - 将curl请求转换成http请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42218219/