curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

getting http return code

From: Jürgen Weber via curl-users <curl-users_at_cool.haxx.se>
Date: Wed, 6 May 2020 15:48:20 +0200

Hi,

many people want to get the http return code from curl to use it in a
script. There are many complicated solutions that parse out the code
from other curl output. The most daring one I found suggests to add a
second stdout: https://superuser.com/a/862395

I think an easier solution would have to be supported by curl:

--return-http-status-code-as-exit-code

if (rc > 100)
   handle HTTP Status code
else
   handle usual curl return code.

Ok, not nice, and not the Unix way, but it would work, if you get a
http code, everything else was fine.

Another way: add a -w template similar to {stderr} to write to a file

-w '%{file:/tmp/curl-http-rc}' '%{response_code}'

Regards,
Juergen
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-05-06