Issue
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?
Solution
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 code
To 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
Answered By - nbari Answer Checked By - Katrina (WPSolving Volunteer)