Hi all,
I'm trying to get a program to log into a server (amazon) with my own credentials to automate some bookkeeping tasks. But the cookies returned from Amazon never end up in the cookie container.
Here is the code sniplet:
CookieContainer Cookies = new CookieContainer(); //Objekt in dem das empfangene Cookie abgelegt wird HttpWebRequest request0 = (HttpWebRequest)WebRequest.Create("https://www.amazon.de/gp/sign-in.html");request0.CookieContainer = Cookies;
HttpWebResponse response = (HttpWebResponse)request0.GetResponse();While the header of the response clearly contains Set-Cookie directives, these don't end up in the cookie container. If I try another url, e.g. http://www.crumhorn-labs/forum, then the cookies end up in the container.
What could be the problem here? I really need this to work! I already tried to work around by reading the cookies of the header and adding them to the container manually, the next server response I need from amazon has two separate set-cookie directives and for some reason only one of them shows up in the header of the response, so the cookies actually get lost.
Any help is greatly appreciated
Thanks
Reiner
andyPosted Dec 16, 2008, 8:36 AM
I'm having same problem. Looking at Set-Cookie I see:
session-id-time=1230019200l; path=/; domain=.amazon.com; expires=Tue Dec 23 08:00:00 2008 GMT
Ah ha--look closely at date. Now look at MSDN doco:
The expiration date is set by using the format expires=date, where date is the expiration date in Greenwich Mean Time (GMT). If the expiration date is not set, the cookie expires after the Internet session ends. Otherwise, the cookie is persisted in the cache until the expiration date. The date must follow the format DAY, DD-MMM-YYYYHH:MM:SS GMT, where DAY is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat), DD is the day in the month (such as 01 for the first day of the month), MMM is the three-letter abbreviation for the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec), YYYY is the year, HH is the hour value in military time (22 would be 10:00 P.M., for example), MM is the minute value, and SS is the second value.
So--date format is not match. Bastards.
To prove, in debugger trap Set-Cookie header and modify format. This works:
session-id=182-0399548-4760358; path=/; domain=.amazon.com; expires=Tue, 23-Dec-2008 08:00:00 GMT
Other than Amazon "fixing" their cookies (ha!) there is no other solution than manual parse.