samedi 20 août 2016

What is the format for a cookie with multiple key value pairs using CURLOPT_COOKIE

I'm scraping a site where, if I use my browser and click through the T.O.S., the page sets a cookie in my browser that looks like this:

Name OnCoreWeb

Value AutoLoadImages=-1&ImageViewer=2&DefaultNumberOfRows=10

The cookie name is OnCoreWeb, but the value is an ampersand delimitted string of three key/value pairs.

When I send the cookie in cURL, I construct it like this:

curl_setopt($ch, CURLOPT_COOKIE, "OnCoreWeb={AutoLoadImages=0&ImageViewer=0&DefaultNumberOfRows=50});

But when I output the headers, the Set-Cookie seems to append an extra value pair to the end of the first cookie, like this:

HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
Set-Cookie: OnCoreWeb={AutoLoadImages=0&ImageViewer=0&DefaultNumberOfRows=50}&AutoLoadImages=-1; expires=Mon, 21-Aug-2017 00:36:44 GMT; path=/
X-Powered-By: ASP.NET

Date: Sun, 21 Aug 2016 00:36:44 GMT

You can see that in the Set-Cookie line, a &AutoLoadImages=-1; is appended right after the closing }. This makes me think my cookie is somehow formatted wrong.

As a control, I've commented out all the COOKIEJAR and COOKIEFILE lines, so that the only cookie setting is done via the CURLOPT_COOKIE property.

Aucun commentaire:

Enregistrer un commentaire