0

I am calling curl to website, checking what http status code and data if returns.

There are 2 cases:

  1. SUCCESS website HTTP status code: 200 (OK) data: none

needed result: CURL exiting with 0 unix status code

  1. FAILURE website HTTP status code: 4xx (error) - could be any data: text data

needed result: CURL exiting with error status code

For now there is used curl with -f modifier (silent).

curl https://mysite.com/something/deploy_status -f

It works great, because it checks the HTTP status code, and return unix error code (22) when there is any problem. However, I need to get also to get the text data, that is sent with error code.

How can I do that? Assume that I can make only one curl call, writing a script is not possible there.

1 Answer 1

2

This is not possible. Its strictly mentioned in curl's manual page -f Fail silently (no output at all) on HTTP errors (H)

So make another curl call to save the html separately.

curl -o output.html YOUR_URL_GOES_HERE

Or use this one that gets you the http status code along with the html page.

curl -s -w %{http_code} http://www.example.com/test -o output.html
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.