I have two web-services

  1. https://localhost/svc/auth which I call first with Authorization headers and I get a cookie

  2. https://localhost/svc/catalog/1234 which I call by providing the cookie set by the 1st call

I am trying to use cURL like this to get the catalog "1234":

curl -u Username:Password -s -i -X GET 'http://localhost/svc/auth' -c /tmp/site-cookie.txt 

curl -b /tmp/site-cookie.txt -s -i -X GET 'http://localhost/svc/article-stock/v1/car/CRH4203052?sid=esi&channel=str&site=0148' 

But this does not work as it seems the cookie have the path set like this:

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

localhost   FALSE   /svc/auth       FALSE   0   MYCOOKIE    VXNlcm5hbWU6RU5DKFFva0VSaDdaMXpKTHRYRHJIUzlvaXVuakVpbURHYmsyaDFRUXlvclA4RD0p

I know I can ask the web-service developer to change the path in its cookie, but I wanted to know if cURL can ignore such path or not to save it?


1 Answer 1


If you are confident in what the server wants, you can edit the cookie after you have received it, and so extend the urls that it applies to. For example, after the first curl command add a sed to remove the trailing part of the url path (/auth):

sed -i -e '/^localhost/s|/auth||' /tmp/site-cookie.txt

then run the second curl and it will pass the cookie as it now matches the start of the url (/svc).

  • Thanks for your answer, in fact it was the only solution I found to bypass this. My question focus on the curl options and if not possible would it be possible with wget instead.
    – рüффп
    Dec 29, 2016 at 21:41
  • If the cookie you get back is always the same you could just supply it explicitly with curl -b MYCOOKIE=VXNl....
    – meuh
    Dec 29, 2016 at 22:34
  • No it's never the same otherwise I would not need to do the first call.
    – рüффп
    Jan 10, 2017 at 21:59
  • Accepted as the best workaround as curl does not have such option.
    – рüффп
    May 5, 2017 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .