How to Get HTTP status code with curl post

blaCkninJa

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?

nbari

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get http status code and content separately using curl in linux

How to get http status code directly into a variable in cURL lib?

cURL Post request: get response and status code

How to read status code from HTTP Post?

Curl and Python Requests (get) reporting different http status code

How to get HTTP status text from HTTP status code?

How to get the status code of the http request?

Perl/ curl How to get Status Code and Response Body

Curl to return http status code along with the response

Getting curl to output HTTP status code?

Bash curl HTTP status code as variable

How to get the status code from HTTP Get in swift?

Get Http Status Code with OkHttp

How to GET/POST a ressource with OAuth 2.0 in JAVA (Status Code 415)

How to get the status code of a CORS http failed preflight requets

How can i get right http status code on sapper?

How can I get the status code from an http error in Axios?

How to get the status code from within the HTTP request handler

How can I get the HTTP status code out of a ServletResponse in a ServletFilter?

How can I get the http status code with javascript?

How do I get an HTTP status code from TTransport exceptions?

how to get Http status code from $resource request

How to get access to Status Code and Error message in HTTP Response

How to get HTTP status code from WinHttp request?

How can I get the Laravel guzzle http status code for 429?

How to get http response status code using JSTL?

laravel : how to get requested url http status code in middleware

PHP + curl, HTTP POST sample code?

HTTP status code 0, how can I confirm a successful result? (cURL and PHP)