[linux] How to post raw body data with curl?

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!

This question is related to linux curl post request http-post

The answer is

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

Questions with linux tag:

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt? How to post raw body data with curl? Copy Files from Windows to the Ubuntu Subsystem How to use local docker images with Minikube? Can Windows Containers be hosted on linux? gradlew command not found? ssh connection refused on Raspberry Pi Composer: file_put_contents(./composer.json): failed to open stream: Permission denied Curl : connection refused boto3 client NoRegionError: You must specify a region error only sometimes gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now sudo: docker-compose: command not found How to upgrade pip3? How can I remove jenkins completely from linux Linux Command History with date and time MySQL fails on: mysql "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded" What is difference between arm64 and armhf? How to redirect output of systemd service to a file Retrieve last 100 lines logs Failed to find Build Tools revision 23.0.1 Run an Ansible task only when the variable contains a specific string What does `set -x` do? How to edit a text file in my terminal Starting a shell in the Docker Alpine container How to run SUDO command in WinSCP to transfer files from Windows to linux Fail during installation of Pillow (Python module) in Linux How to install Android SDK on Ubuntu? How do I delete virtual interface in Linux? What is the default root pasword for MySQL 5.7 Docker command can't connect to Docker daemon How to find files modified in last x minutes (find -mmin does not work as expected) Can I use Homebrew on Ubuntu? Pycharm and sys.argv arguments Ubuntu: OpenJDK 8 - Unable to locate package Fork() function in C Amazon Linux: apt-get: command not found Ionic android build Error - Failed to find 'ANDROID_HOME' environment variable Ubuntu: Using curl to download an image Docker error response from daemon: "Conflict ... already in use by container" Curl command without using cache Can't get private key with openssl (no start line:pem_lib.c:703:Expecting: ANY PRIVATE KEY)

Questions with curl tag:

What is the incentive for curl to release the library for free? curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number Converting a POSTMAN request to Curl git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to post raw body data with curl? Curl : connection refused How to use the curl command in PowerShell? Curl to return http status code along with the response How to install php-curl in Ubuntu 16.04 curl: (35) SSL connect error Solving sslv3 alert handshake failure when trying to use a client certificate curl: (6) Could not resolve host: application How do I install the ext-curl extension with PHP 7? Ubuntu: Using curl to download an image Curl command without using cache Using client certificate in Curl command PHP: Call to undefined function: simplexml_load_string() Adding subscribers to a list using Mailchimp's API v3 Correct way to set Bearer token with CURL Making an API call in Python with an API that requires a bearer token cURL error 60: SSL certificate: unable to get local issuer certificate Upload Image using POST form data in Python-requests PHP - SSL certificate error: unable to get local issuer certificate How to use curl to get a GET request exactly same as using Chrome? Curl not recognized as an internal or external command, operable program or batch file Simulate a specific CURL in PostMan Display curl output in readable JSON format in Unix shell script pass JSON to HTTP POST Request Execute curl command within a Python script How to define the basic HTTP authentication using cURL correctly? Perform curl request in javascript? How to use Python to execute a cURL command? wget/curl large file from google drive curl: (6) Could not resolve host: google.com; Name or service not known curl: (60) SSL certificate problem: unable to get local issuer certificate how to get curl to output only http response body (json) and no other headers etc Unable to resolve "unable to get local issuer certificate" using git on Windows with self-signed certificate curl Failed to connect to localhost port 80 How to insert data into elasticsearch Basic HTTP and Bearer Token Authentication Creating a REST API using PHP Posting raw image data as multipart/form-data in curl Curl error: Operation timed out POST request send json data java HttpUrlConnection How to count items in JSON object using command line? Curl GET request with json parameter Curl and PHP - how can I pass a json through curl by PUT,POST,GET Curl error 60, SSL certificate issue: self signed certificate in certificate chain PHP cURL error code 60 Curl: Fix CURL (51) SSL error: no alternative certificate subject name matches

Questions with post tag:

How to post query parameters with Axios? How can I add raw data body to an axios request? HTTP POST with Json on Body - Flutter/Dart How do I POST XML data to a webservice with Postman? How to set header and options in axios? Redirecting to a page after submitting form in HTML How to post raw body data with curl? How do I make a https post in Node Js without any third party module? How to convert an object to JSON correctly in Angular 2 with TypeScript Postman: How to make multiple requests at the same time How to send a POST request from node.js Express? How to make HTTP Post request with JSON body in Swift Send Post Request with params using Retrofit C#: HttpClient with POST parameters HTTP Request in Swift with POST method How to use jquery $.post() method to submit form values Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers AngularJS - $http.post send data as json Sending a JSON to server and retrieving a JSON in return, without JQuery Angularjs how to upload multipart form data and a file? What's the difference between "Request Payload" vs "Form Data" as seen in Chrome dev tools Network tab How to skip the OPTIONS preflight request? Send value of submit button when form gets posted How to create JSON post to api using C# POST request send json data java HttpUrlConnection Curl and PHP - how can I pass a json through curl by PUT,POST,GET Making href (anchor tag) request POST instead of GET? How to get POSTed JSON in Flask? How to upload file to server with HTTP POST multipart/form-data? REST API using POST instead of GET Spring MVC - Why not able to use @RequestBody and @RequestParam together 415 Unsupported Media Type - POST json to OData service in lightswitch 2012 403 Forbidden error when making an ajax Post request in Django framework AngularJs $http.post() does not send data What is the right way to POST multipart/form-data using curl? jQuery - Redirect with post data Reading JSON POST using PHP Receive JSON POST with PHP How to access the php.ini from my CPanel? fix java.net.SocketTimeoutException: Read timed out How to add additional fields to form before submit? Post request with Wget? JQuery Ajax POST in Codeigniter jQuery .ajax() POST Request throws 405 (Method Not Allowed) on RESTful WCF Pass Hidden parameters using response.sendRedirect() POST request with JSON body Pass variables between two PHP pages without using a form or the URL of page POST: sending a post request in a url itself Getting 400 bad request error in Jquery Ajax POST How to send file contents as body entity using cURL

Questions with request tag:

How to send Basic Auth with axios How to post raw body data with curl? Pandas read_csv from url POST request with a simple string in body with Alamofire PHP GuzzleHttp. How to make a post request with params? How to modify the nodejs request default timeout time? Doing HTTP requests FROM Laravel to an external API CORS jQuery AJAX request Node.js request CERT_HAS_EXPIRED What is the difference between response.sendRedirect() and request.getRequestDispatcher().forward(request,response) Unable to verify leaf signature How to get data out of a Node.js http get request Node.js - get raw request body using Express installing requests module in python 2.7 windows How to add Headers on RESTful call using Jersey Client API Write in body request with HttpClient Node.js: How to send headers with form data using request module? Correct way to try/except using Python requests module? How can I mock requests and the response? node-request - Getting error "SSL23_GET_SERVER_HELLO:unknown protocol" How are parameters sent in an HTTP POST request? HTTP client timeout and server timeout Spring MVC How take the parameter value of a GET HTTP Request in my controller method? PHP CURL DELETE request How to obtain values of request variables using Python and Flask Getting all request parameters in Symfony 2 Display PNG image as response to jQuery AJAX request Python send POST with header Difference between Pragma and Cache-Control headers? Bad Request, Your browser sent a request that this server could not understand Tomcat request timeout POST data with request module on Node.JS Javascript : Send JSON Object with Ajax? How do I send a POST request with PHP? Parsing GET request parameters in a URL that contains another URL get current page from url How to make a HTTP request using Ruby on Rails? Django request.GET Show Curl POST Request Headers? Is there a way to do this? How can I run multiple curl requests processed sequentially? How to use a servlet filter in Java to change an incoming servlet request url? Where can I find the default timeout settings for all browsers? Post to another page within a PHP script Get Request and Session Parameters and Attributes from JSF pages Detecting request type in PHP (GET, POST, PUT or DELETE) HTTP GET in VBS

Questions with http-post tag:

Passing headers with axios POST request How to post raw body data with curl? Send FormData with other field in AngularJS How do I POST a x-www-form-urlencoded request using Fetch? OkHttp Post Body as JSON What is the difference between PUT, POST and PATCH? HTTP Request in Swift with POST method Uploading file using POST request in Node.js Send POST request with JSON data using Volley AngularJS $http-post - convert binary to excel file and download Simple C example of doing an HTTP POST and consuming the response How to POST raw whole JSON in the body of a Retrofit request? Uploading Images to Server android How to Get the HTTP Post data in C#? Spring MVC - Why not able to use @RequestBody and @RequestParam together Simple post to Web Api How do I print the content of httprequest request? How to simulate POST request? How to POST URL in data of a curl request Sending an HTTP POST request on iOS Node.js - How to send data from html to express $_POST not working. "Notice: Undefined index: username..." How to add parameters to HttpURLConnection using POST using NameValuePair How to set a Header field on POST a form? ios Upload Image and Text using HTTP POST Get all variables sent with POST? How to use parameters with HttpPost Reading file input from a multipart/form-data POST Access POST values in Symfony2 request object Should I URL-encode POST data? Send request to curl with post data sourced from a file Pure JavaScript Send POST Data Without a Form How can I use JQuery to post JSON data? Send json post using php How can I pass POST parameters in a URL? Using HttpClient and HttpPost in Android with post parameters submit a form in a new tab How to retrieve form values from HTTPPOST, dictionary or? Logging POST data from $request_body How to manually send HTTP POST requests from Firefox or Chrome browser? Android, Java: HTTP POST Request How to use type: "POST" in jsonp ajax call How to process POST data in Node.js? .NET: Simplest way to send POST with data and read response Is there a max size for POST parameter content? Prevent double submission of forms in jQuery How to post data in PHP using file_get_contents? Getting a POST variable PHP + curl, HTTP POST sample code? Values of disabled inputs will not be submitted