Richard <[email protected]> wrote:

>  
>  Hi,
> 
> 
> I have write a simple program based on libcur, it simpley download data and 
> write to a local file.
> In most of the cases, it works fine, but some special case, it works 
> differently from linux curl command.
> 
> The main part of my program looks like this:
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> 62       CURL* handler = curl_easy_init();
> 65      int ret = CURLE_OK;
> 266     ret += curl_easy_setopt(handler, CURLOPT_ERRORBUFFER, errBuffer);
> 267     ret += curl_easy_setopt(handler, CURLOPT_VERBOSE, 1);
> 268     ret += curl_easy_setopt(handler, CURLOPT_URL, url);
> 
> 270     ret += curl_easy_setopt(handler, CURLOPT_WRITEFUNCTION, 
> write_image_data);
> 271     ret += curl_easy_setopt(handler, CURLOPT_WRITEDATA, imgData);
> 
> 273     ret += curl_easy_perform(handler);
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> 
> In a special case, this url:
> http://www.my7475.com/wp-content/uploads/2008/09/my747508093002.jpg
> My program fails in getting image, the printed out message looks like this:
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> * About to connect() to www.my7475.com port 80
> *   Trying 119.57.53.145... * connected
> * Connected to www.my7475.com (119.57.53.145) port 80
> > GET /wp-content/uploads/2008/09/my747508093002.jpg HTTP/1.1
> Host: www.my7475.com
> Accept: */*
> 
> < HTTP/1.1 500 Internal Server Error
> < Date: Tue, 14 Jun 2011 07:44:48 GMT
> < Server: Apache/2.2.15 (Unix) PHP/5.2.13
> < Content-Length: 535
> < Connection: close
> < Content-Type: text/html; charset=iso-8859-1
> * Closing connection #0
> download size: 535
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> I checked the downloaded content, it is just a text message telling me 
> internal server error.
> But if I use curl with default option and verbose mode, it download the image 
> succesfully
> and print out message like this:
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
> * About to connect() to www.my7475.com port 80
> *   Trying 119.57.53.145... connected
> * Connected to www.my7475.com (119.57.53.145) port 80
> > GET /wp-content/uploads/2008/09/my747508093002.jpg HTTP/1.1
> > User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 
> > OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> > Host: www.my7475.com
> > Accept: */*
> >
> < HTTP/1.1 200 OK
> < Date: Tue, 14 Jun 2011 07:46:22 GMT
> < Server: Apache/2.2.15 (Unix) PHP/5.2.13
> < Last-Modified: Fri, 19 Mar 2010 12:46:33 GMT
> < ETag: "19689e6-5a17-48226bcb21c40"
> < Accept-Ranges: bytes
> < Content-Length: 23063
> < Content-Type: image/jpeg
>   % Total    % Received % Xferd  Average Speed   Time    Time     Time  
> Current
>                                  Dload  Upload   Total   Spent    Left  Speed
> 100 23063  100 23063    0     0   6216      0  0:00:03  0:00:03 --:--:--  
> 410kConnection #0 to host www.my7475.com left intact
> 
> * Closing connection #0
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////
> 
> From the above two verbose messages, it is really hard for me to figure out 
> what is wrong.

The server seems to be expecting an User-Agent:

fk@r500 ~ $curl --head 
'http://www.my7475.com/wp-content/uploads/2008/09/my747508093002.jpg'
HTTP/1.1 200 OK
Date: Tue, 14 Jun 2011 08:27:27 GMT
Server: Apache/2.2.15 (Unix) PHP/5.2.13
Last-Modified: Sat, 12 Feb 2011 02:53:52 GMT
ETag: "19689e6-5a17-48226bcb21c40"
Accept-Ranges: bytes
Content-Length: 23063
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Content-Type: image/jpeg
Proxy-Connection: keep-alive

fk@r500 ~ $curl -H 'User-Agent:' --head 
'http://www.my7475.com/wp-content/uploads/2008/09/my747508093002.jpg'
HTTP/1.1 500 Internal Server Error
Date: Tue, 14 Jun 2011 08:27:41 GMT
Server: Apache/2.2.15 (Unix) PHP/5.2.13
Connection: close
Content-Type: text/html; charset=iso-8859-1
Proxy-Connection: keep-alive

Fabian

Attachment: signature.asc
Description: PGP signature

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to