3

I just wanted to know what is the way to get the return code from the curl command. Likewise, if trigger the same curl from postman client we are able to get all error messages.

Currently, I am just able to get the return code as "0" in case of success but I wanted "200" and other return code with respect to the command.

curl -X POST http://localhost:4449/api/messages -H 'accept: application/json' -H 'authorization: Basic cmVsYXktnruDFjEyMw==' -H 'content-type: application/json' -d "{\"cloudDelivery\":\"$cloudDelivery\"}"
Inian
  • 80,270
  • 14
  • 142
  • 161
Indrajeet Gour
  • 4,020
  • 5
  • 43
  • 70

2 Answers2

2

Use the -I option to get the status code on the first line of the response:

$ curl -I www.google.com
 HTTP/1.1 200 OK
 Date: Wed, 06 Feb 2019 12:58:31 GMT
 ...

There is a whole exchange about this question here.

They propose a simple way to get only the code with the next command:

curl -s -o /dev/null -I -w "%{http_code}" http://www.example.org/
-3

This is called "http status code".

Just Google "curl http status code" and you will find the answer:

https://superuser.com/questions/272265/getting-curl-to-output-http-status-code

nullPointer
  • 4,419
  • 1
  • 15
  • 27
Null
  • 657
  • 2
  • 6
  • 15