cURL Option to show HTTP Response Status Code


In order to know the HTTP(S) Response status code using cURL command, make use of the -I option to display the response headers.

Example:
% $ curl -I https://google.com
HTTP/2 301 
location: https://www.google.com/
content-type: text/html; charset=UTF-8
cross-origin-opener-policy-report-only: same-origin-allow-popups; report-to="gws"
date: Mon, 12 Dec 2022 09:38:06 GMT
expires: Wed, 11 Jan 2023 09:38:06 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN

If you just want to display the HTTP response status code, make use of the -s option and pipe it with awk 'NR==1' to just display the 1st line.

% curl -Is https://google.com | awk 'NR==1'
HTTP/2 301 
% curl -Is https://code2care.org | awk 'NR==1'
HTTP/2 200 
curl -Is https://google.com/code2care | awk 'NR==1'
HTTP/2 404
cURL to show the HTTP Response Status Code

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap