cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Posting to asp script and retrieving image

From: Phillip Thatcher <p.thatcher_at_jupiter-electric.com>
Date: Fri, 23 Sep 2005 11:27:52 -0500

I've got an issue I've been working on for the past few days. I am using
PHP/CURL to log onto a secure site (https), navigate to a page that lists a
lot of images (links look like <a
href="https://www.example.com/dir1/dir2/download.asp?f=/all/img1.gif">img1.g
if</a>) which I pull links via regex, and then I try this:

$headers = "
POST http://www.example.com/dir1/dir2/download.asp HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer: http://www.example.com/dir1/dir2/download.asp?Dldr=/all
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
1.1.4322)
Host: www.example.com
Content-Length: 33
Proxy-Connection: Keep-Alive
Pragma: no-cache

f=%2Fall%2F$img1.gif&Submit=Submit
";
curl_setopt ($ch, CURLOPT_URL,
'http://www.example.com/dir1/dir2/download.asp');
curl_setopt ($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'f=%2Fall%2Fimg1.gif);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $CookieFile);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $headers);
$content = curl_exec ($ch);
curl_close($ch);
echo "{Content}<p>&nbsp;</p>$content<p>&nbsp;</p>{/Content}";

if($file=fopen("img1.gif", "w")) { //open file for writing
        fwrite($file, $content); //write to file
        echo 'img1.gif';
}

I recorded the headers from ieHTTPHeaders and LiveHTTPHeaders (for FireFox)
to get the $headers information, when sending request to download.asp in
browser, it pops up a save file as or open dialog box as it is suppose to,
but I can't seem to get CURL to download the image and save to file. The
file gets written as a 0k file, and the $content echo'd back is blank, I
removed the headers info to make the page return a "user must be logged in"
and $content records that data, but will not download the image that is
suppose to be coming in, any ideas?

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2005-09-23