如何张贴原始身体数据与卷曲?

在你以副本的形式发布这篇文章之前,我已经尝试了我在 SO 周围找到的许多建议。

到目前为止,我一直在使用 postman 将数据发布到 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/

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

有人知道我做错了什么吗?我的卷发请求和我的邮递员请求有什么不同?欢迎任何提示!

305107 次浏览

curl's --data will by default send Content-Type: application/x-www-form-urlencoded in the request header. However, when using Postman's raw body mode, Postman sends Content-Type: text/plain in the request header.

So to achieve the same thing as Postman, specify -H "Content-Type: text/plain" for curl:

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

Note that if you want to watch the full request sent by Postman, you can enable debugging for packed app. Check this link for all instructions. Then you can inspect the app (right-click in Postman) and view all requests sent from Postman in the network tab :

enter image description here