如何用curl发布原始身体数据?

时间:2017-03-27 18:47:17

标签: linux curl post request http-post

在您将其作为副本发布之前;我已经尝试了很多关于SO的建议。

到目前为止,我一直在使用邮递员将数据发布到Java Web服务。这很有效,如下:

enter image description here

我现在想用curl做同样的事情,所以我尝试使用以下方法:

$ curl -X POST --data "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data "@/home/kramer65/afile.txt" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "@/home/kramer65/afile.txt" http://78.41.xx.xx:7778/

不幸的是,所有这些都显示接收方空的原始身体。

有人知道我在这里做错了什么吗?我的卷发请求与我的邮递员请求有什么不同?欢迎所有提示!

1 个答案:

答案 0 :(得分:48)

curl的--data默认会在请求标头中发送Content-Type: application/x-www-form-urlencoded。但是,在使用Postman的raw正文模式时,Postman会在请求标头中发送Content-Type: text/plain

为了实现与Postman相同的功能,请为curl指定-H "Content-Type: text/plain"

curl -X POST -H "Content-Type: text/plain" --data "this is raw data" http://78.41.xx.xx:7778/

请注意,如果您想观看Postman发送的完整请求,您可以启用打包应用的调试。查看this link以获取所有说明。然后,您可以检查应用程序(右键单击Postman)并查看Postman在network选项卡中发送的所有请求:

enter image description here

相关问题