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.

Re: getting http return code

From: Daniel Stenberg via curl-users <curl-users_at_cool.haxx.se>
Date: Wed, 6 May 2020 15:59:24 +0200 (CEST)

On Wed, 6 May 2020, Jürgen Weber via curl-users wrote:

> 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

I don't understand why we'd need that (and I would have a problem with that
particular approach). In most use cases, you'll be fine with something simple
like this:

   code=`curl -w '%{response_code}' -o saved $URL`

-- 
  / daniel.haxx.se | Commercial curl support up to 24x7 is available!
                   | Private help, bug fixes, support, ports, new features
                   | https://www.wolfssl.com/contact/

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