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: Pierre Brico via curl-users <curl-users_at_cool.haxx.se>
Date: Wed, 6 May 2020 21:00:57 +0200

On Wed, May 6, 2020 at 4:08 PM Daniel Stenberg via curl-users <
curl-users_at_cool.haxx.se> wrote:

> 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`
>
>
>
I would add that return codes are between 0 (success) and 255.

How do you return HTTP code 404 ?

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