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: Jürgen Weber via curl-users <curl-users_at_cool.haxx.se>
Date: Fri, 8 May 2020 07:22:09 +0200

I am good with --dump-header

That's easy enough, thank you.

Am Fr., 8. Mai 2020 um 00:18 Uhr schrieb Коваленко Анатолий Викторович
via curl-users <curl-users_at_cool.haxx.se>:
>
> There is very simple solution: -D (--dump-header) Dump.txt and parse the FIRST line. Return code –
> between first and second spaces (both 1.1 and 2 versions of HTTP).
>
> And you can process complex dumps (when there are multiple SUBheaders, with -L option).
>
> > 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
>
>
> -----------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
> Etiquette: https://curl.haxx.se/mail/etiquette.html

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