How to post raw body data with curl?

LinuxCurlPostRequestHttp Post

Linux Problem Overview


Before you post this as a duplicate; I've tried many of the suggestions I found around SO.

So far I've been using postman to post data to a Java web service. That works great as follows:

enter image description here

I now want to do the same using curl, so I tried it using the following ways:

$ 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/

Unfortunately, all of those show an empty raw body on the receiving side.

Does anybody know what I'm doing wrong here? How is my curl request different from my postman request? All tips are welcome!

Linux Solutions


Solution 1 - Linux

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionkramer65View Question on Stackoverflow
Solution 1 - LinuxBertrand MartelView Answer on Stackoverflow