// JP opened flex table

Click to See Complete Forum and Search --> : Cookies and URLDownloadToFile?


betonboor
November 25th, 2007, 02:13 PM
Hi,

Here's my problem: I need to download some website content. I've created a simple c++ program for this which uses URLDownloadToFile(), which works just fine!
However, a part of the site is behind login and therefor it requires cookies to access it. I have the login and cookie but I don't know how to use it in c++ so that it can download from those pages.

Is there some sort of function in which you can add a cookie and then call some download function (like URLDownloadToFile)?

I normally use URLDownloadToFile with this link: http://[site]/filedownload.php?id=[id]
However it only gives back files with a message "You need cookies enabled in your browser".

Thanks,
betonboor

betonboor
November 26th, 2007, 10:38 AM
Anyone???

I've already found this article: http://www.codeguru.com/csharp/csharp/cs_network/internetweb/comments.php/c7005/?thread=1163

However it only explains that you can use WebRequest / WebResponse to attach cookies, and that is csharp (which I don't know). I only know c++...

So is there some sort of function that can do the same in c++?

Thanks,
Betonboor

MikeAThon
November 26th, 2007, 11:52 AM
Cookies are part of the HTTP "GET" request. They are in the header. Your program must parse the response to initial HTTP "GET" request, which typically has a cookie at the end of the responsive header. Then your program must return the cookie in subsequent "GET" requests.

I am not certain if the URLDownloadToFile function will allow you to append cookies to the "GET" request that it manufactures and sends on your behalf.

Mike

betonboor
November 26th, 2007, 03:30 PM
Thanks for your reply! It makes sense that cookies are part of the GET request, and that they therefor need to be added to the GET request.

Problem is that I don't know how to send such a request to a server (and receive the corresponding data) in c++ (including the cookie and all)...

Got any more hints or tips? I've been googling all over the place but can't find any good answers to my problem.

I've also tried it in PHP (using libcurl). No luck though...

Thanks,
betonboor

MikeAThon
November 26th, 2007, 06:59 PM
Read these two RFCs:

RFC2965: "HTTP State Management Mechanism", D. Kristol, L. Montulli October 2000 (Obsoletes RFC2109) at ftp://ftp.rfc-editor.org/in-notes/rfc2965.txt

RFC2109: "HTTP State Management Mechanism ", D. Kristol, L. Montulli February 1997 (Obsoleted by RFC2965) at ftp://ftp.rfc-editor.org/in-notes/rfc2109.txt

The examples in each are helpful. For rfc 2965, the examples start at page 14, and those for rfc 2109 start at page 11.

Mike

betonboor
November 27th, 2007, 05:14 AM
Thanks a lot!! I'll ready them through when I get home.

//JP added flex table