Forum Moderators: coopster

Message Too Old, No Replies

Using proxy's in curl

I get several errors when I try to use a proxy wit curl

         

bluedevs

3:47 pm on Oct 26, 2005 (gmt 0)

10+ Year Member




<?php
$url = 'http://whatismyip.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '128.114.63.15:3128');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_exec ($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
echo '<br />';
print_r($curl_info);
?>

This results in:
HTTP/1.0 405 Method Not Allowed Content-Type: text/html Allow: GET
Array ( [url] => [whatismyip.com...] [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0.004 [connect_time] => 0.162 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0 [redirect_time] => 0 )

The proxy I used was just an example. No proxy worked for me...

Does anyone know a solution?

Thanks in advance,
John

soflution

8:12 pm on Oct 26, 2005 (gmt 0)

10+ Year Member



Why do you use: curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');?

bluedevs

8:58 pm on Oct 26, 2005 (gmt 0)

10+ Year Member



'cause I hope it helped, but it didn't. Fair enough, without that line it doesn't work either...

anyone?

jatar_k

9:00 pm on Oct 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe this will help
405 Method Not Allowed
The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.

from
[w3.org...]

bluedevs

9:09 pm on Oct 26, 2005 (gmt 0)

10+ Year Member



Yes, I've read that too, but I thought the default request was GET. I've even said it explicit with this line: curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET')

so, I don't understand...

jatar_k

9:23 pm on Oct 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you shouldn't need CURLOPT_CUSTOMREQUEST at all

you should start with something really simple to see if it works, add 1 option at a time to see what is actually breaking it.

bluedevs

9:24 pm on Oct 26, 2005 (gmt 0)

10+ Year Member



I've found the answer my self :D

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

changing in:

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);

was the solution.

thanks anyway!

jatar_k

9:54 pm on Oct 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



nice work