I'm using curl for GET at the command line on Linux in order to get http response code. The response bodies are printed to standard out, which is fine, but I can't see any solution how to get curl for POST to print the HTTP status code(200, 404, 403 etc). Is this possible?
To get only the http_code
you could try:
curl -s -o /dev/null --head -w "%{http_code}" -X POST "https://httpbin.org/post"
you can read/remember it like:
-s
Silent mode -o
Write output to /dev/null --head
Get headers
only-w "%{http_code}"
write out the HTTP Status codeTo get all the headers from your request try:
curl -I -X POST "https://httpbin.org/post"
It will return something like:
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Thu, 28 Mar 2019 20:12:01 GMT
Server: nginx
Content-Length: 294
Connection: keep-alive
curl -X POST --write-out %{http_code} --silent --output /dev/null --data "{your_json_input}}" -H 'Content-Type:application/json' http://your_url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With