cURL / Mailing Lists / curl-library / Single Mail

curl-library

Cannot retrieve "301 Moved Permanently" file

From: Valentine Rozental <valentine.rozental_at_gmail.com>
Date: Wed, 28 Sep 2011 07:24:16 -0600

Hello,

I cannot to retrieve a file if there is "301 Moved Permanently" redirection.
The 'easy' interface is used and the CURLOPT_FOLLOWLOCATION is set
successfully by:
curl_easy_setopt(easyHandle, CURLOPT_FOLLOWLOCATION, 1)

The good example will be provided if you try to retrieve the file from:
https://plus.google.com/favicon.ico

The file that I get back instead of the requested is the google 404
error page.

I've ran the command line curl and this is what get:

valentine_at_cyberw:~/test[06:28:26 AM]$ curl -v -L -o ./curl_favicon.ico
https://plus.google.com/favicon.ico
* About to connect() to plus.google.com port 443 (#0)
* Trying 74.125.226.42... connected
* Connected to plus.google.com (74.125.226.42) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
   CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
* SSLv3, TLS handshake, CERT (11):
{ [data not shown]
* SSLv3, TLS handshake, Server finished (14):
{ [data not shown]
* SSLv3, TLS handshake, Client key exchange (16):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Finished (20):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
{ [data not shown]
* SSLv3, TLS handshake, Finished (20):
{ [data not shown]
* SSL connection using RC4-SHA
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc;
CN=*.google.com
* start date: 2011-09-05 06:05:49 GMT
* expire date: 2012-09-05 06:15:49 GMT
* subjectAltName: plus.google.com matched
* issuer: C=US; O=Google Inc; CN=Google Internet Authority
* SSL certificate verify ok.
> GET /favicon.ico HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7
OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: plus.google.com
> Accept: */*
>
   % Total % Received % Xferd Average Speed Time Time Time
Current
                                  Dload Upload Total Spent Left
Speed
   0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0< HTTP/1.1 301 Moved Permanently
< Content-Type: text/html; charset=UTF-8
< Location: //ssl.gstatic.com/s2/oz/images/favicon.ico
< Date: Wed, 28 Sep 2011 12:31:32 GMT
< Expires: Wed, 28 Sep 2011 12:31:32 GMT
< Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Transfer-Encoding: chunked
<
* Ignoring the response-body
{ [data not shown]
112 224 0 224 0 0 617 0 --:--:-- --:--:--
--:--:-- 2545* Connection #0 to host plus.google.com left intact
* Issue another request to this URL:
'https://plus.google.com//ssl.gstatic.com/s2/oz/images/favicon.ico'
* Re-using existing connection! (#0) with host plus.google.com
* Connected to plus.google.com (74.125.226.42) port 443 (#0)
> GET //ssl.gstatic.com/s2/oz/images/favicon.ico HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7
OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: plus.google.com
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/html; charset=utf-8
< Date: Wed, 28 Sep 2011 12:31:32 GMT
< Expires: Wed, 28 Sep 2011 12:31:32 GMT
< Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Transfer-Encoding: chunked
<
{ [data not shown]
100 11744 0 11744 0 0 22642 0 --:--:-- --:--:-- --:--:--
91436* Connection #0 to host plus.google.com left intact

* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
} [data not shown]

The curl requests the "https://plus.google.com/favicon.ico"
but the redirection gives the new location:
"//ssl.gstatic.com/s2/oz/images/favicon.ico"
then the curl issues the request from
"https://plus.google.com//ssl.gstatic.com/s2/oz/images/favicon.ico".

Why it happens?
Can someone explanation it?

Thank you in advance,
Valentine.

p.s. The wget does it as follow:

valentine_at_cyberw:~/test[07:24:01 AM]$ wget
https://plus.google.com/favicon.ico
--2011-09-28 07:24:05-- https://plus.google.com/favicon.ico
Resolving plus.google.com... 74.125.226.44, 74.125.226.45,
74.125.226.46, ...
Connecting to plus.google.com|74.125.226.44|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: //ssl.gstatic.com/s2/oz/images/favicon.ico [following]
--2011-09-28 07:24:05-- https://ssl.gstatic.com/s2/oz/images/favicon.ico
Resolving ssl.gstatic.com... 209.85.145.120
Connecting to ssl.gstatic.com|209.85.145.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1150 (1.1K) [image/x-icon]
Saving to: `favicon.ico.1'

100%[===================================================================================================================>]
1,150 --.-K/s in 0s

2011-09-28 07:24:06 (6.66 MB/s) - `favicon.ico.1' saved [1150/1150]

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-09-28