Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

curl - http-version

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hey,

The following code works on my local server, but not on my host. It's 'cause I use http/1.1 and my host uses http/1.0. When I execute following code in my host I get the following error:

Code:
curl_setopt($ch, CURLOPT_URL, "[URL unfurl="true"]http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID="[/URL] . $fid);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookie.txt');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_myspace_home);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$pagecontents = curl_exec($ch);

echo $pagecontents;

error I get:

HTTP/1.0 302 Moved Temporarily
Object moved to here.


So this is 'cause of the http/1.O. So I thought off using curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');. But it still use http/1.0. I don't know where to put it or if it's correct. There is so little information about this tag.

Anyone any experience in changing the http version with php?

The One And Only KryptoS
 
This:

HTTP/1.0 302 Moved Temporarily
Object moved to here.

is an HTTP response header generated by the server. No matter what you do with your HTTP version, that server is going to respond with that HTTP version.


Want the best answers? Ask the best questions! TANSTAAFL!
 
what use does CURLOPT_HTTP_VERSION have if it's always using the server http response header?

Can u suggest somethings else that I can use to do the same?

thanks for the answer


The One And Only KryptoS
 
I'm not completely sure what you're asking.

But if you're trying to force cURL to use HTTP version 1.1, your invocation of curl_setop() is likely wrong.

Don't do:

curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');

do:

url_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

like CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 is a constant and should not be in quotes.


Want the best answers? Ask the best questions! TANSTAAFL!
 
yes I would like to use 1.1 and I tried to do it with curl_setop().
'Cause my host is using 1.0 and that won't work.

But I also tried it without the quotes and I still get the same error.

HTTP/1.0 302 Moved Temporarily
Object moved to here.


I think it would be easier just asking the host if he can change it. So that he'll use 1.1 :).
Don't know if that's possible for him.

It's not all clear for me. Who's sending the header http/1.O? My host? Or the website I call in my curl (in my case:
The One And Only KryptoS
 
As I said before, this:

HTTP/1.0 302 Moved Temporarily
Object moved to here.

is sent by the website you call in your cURL invocation.


Anyway, what you're getting is NOT an error. It's a perfectly valid HTTP responce from the myspace server. (If you don't recognize it as such, I strongly recommend that you bone up on your understanding of the HTTP spec. It can be found at Also, see section 2.6 of my FAQ: faq434-2999) If you look at all the HTTP headers that the myspace site is sending, you'll certainly see a header beginning "Location:". If you are opening the site with a browser, your browser would automatically go to the URL specified in the "Location" header.


Want the best answers? Ask the best questions! TANSTAAFL!
 
let's discus this further :)

1. I know it's not a real error. But it's not what I want. So it's an error for me :).

2. if the header is send by the website I invocate in my cURL why does it give on local server HTTP/1.1 and on my host server HTTP/1.0?

Code:
curl_setopt($ch, CURLOPT_URL, "[URL unfurl="true"]http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID="[/URL] . $fid);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookie.txt');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_myspace_home);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$pagecontents = curl_exec($ch);

echo $pagecontents;

output $pagecontents on my local server:
Code:
HTTP/1.1 200 OK Cache-Control: private Pragma: no-cache Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8 Expires: Thu, 30 Sep 1999 01:29:07 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Set-Cookie: FLANG=en; path=/ X-Server: ELS1MWEBBLU0119 Date: Tue, 23 Jan 2007 17:02:58 GMT

output $pagecontents on my host server:
Code:
HTTP/1.0 302 Moved Temporarily Date: Tue, 23 Jan 2007 17:03:44 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Location: [URL unfurl="true"]http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=6221[/URL] Set-Cookie: MSCulture=IP=64.202.165.131&IPCulture=en-US&PreferredCulture=en-US&Country=US; domain=myspace.com; expires=Tue, 30-Jan-2007 17:03:44 GMT; path=/ Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 206 X-Cache: MISS from wc01.inet.mesa1.secureserver.net Connection: close

The One And Only KryptoS
 
First, let's reformat the output from the two runs:

From your server:
Code:
HTTP/1.1 200 OK
Cache-Control: private
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
Expires: Thu, 30 Sep 1999 01:29:07 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Set-Cookie: FLANG=en; path=/
X-Server: ELS1MWEBBLU0119
Date: Tue, 23 Jan 2007 17:02:58 GMT

And from your hosting server:
Code:
HTTP/1.0 302 Moved Temporarily
Date: Tue, 23 Jan 2007 17:03:44 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Location: [URL unfurl="true"]http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=6221[/URL]
Set-Cookie: MSCulture=IP=64.202.165.131&IPCulture=en-US&PreferredCulture=en-US&Country=US; domain=myspace.com; expires=Tue, 30-Jan-2007 17:03:44 GMT; path=/
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 206
X-Cache: MISS from wc01.inet.mesa1.secureserver.net
Connection: close

The second-to-last line from the hosting server seems significant to me:

X-Cache: MISS from wc01.inet.mesa1.secureserver.net

it looks like your hosting service has some kind of proxy running. Check with them.


Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top