How do I get my curl status code?

How do I get my curl status code?

17 Answers

  1. 186.
  2. And to get just the status number, pipe it to head -n 1|cut -d$’ ‘ -f2.
  3. Following the redirect after only doing a HEAD request may cause interesting behavior, depending on how the app is programmed.
  4. curl -I -X GET will send a GET request, but give the same output.

How do I get a status code?

In the main window of the program, enter your website homepage URL and click on the ‘Start’ button. As soon as crawling is complete, you will have all status codes in the corresponding table column. Pages with the 4xx and 5xx HTTP status codes will be gathered into special issue reports.

How do you capture responses in curl?

By default, curl doesn’t print the response headers. It only prints the response body. To print the response headers, too, use the -i command line argument.

How do I copy curl output to a file?

For those of you want to copy the cURL output in the clipboard instead of outputting to a file, you can use pbcopy by using the pipe | after the cURL command. Example: curl https://www.google.com/robots.txt | pbcopy . This will copy all the content from the given URL to your clipboard.

How to get HTTP status code with Curl post?

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:

How to tell curl to read format from stdin?

The format can be specified as a literal “string”, or you can have curl read the format from a file with “@filename” and to tell curl to read the format from stdin you write “@-“. The variables present in the output format will be substituted by the value or text that curl thinks fit, as described below.

How to get the header and body of curl?

To get both (header and body), I usually perform a curl -D- as in: This will dump headers ( -D) to stdout ( -) (Look for –dump-header in man curl ). I often use jq to get that json data (eg from some rest APIs) formatted. But as jq doesn’t expect a HTTP header, the trick is to print headers to stderr using -D/dev/stderr.

When to use the-F flag in curl?

Note that without the -f flag, curl won’t return non-zero error codes when the server returns an abnormal HTTP response code i.e. >=400, and with the -f flag, server output is suppresses on error, making use of this flag for error-detection and processing unattractive.