HTTP request with proxy

HTTP request with proxy

am 02.10.2007 05:10:51 von Tim Arview

Hello,

I am working on a project to access a web page through a proxy. I do
not host the script myself, but upload it to my hosting provider. The
version of PHP on that server is 4.4.6.

I have attempted using fsockopen as well as cURL to accomplish this
task, but it won't seem to work. Here is the important bits of the
code I am using:

$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
curl_setopt( $ch, CURLOPT_PROXY, $proxy . ":" . $port );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
if( !curl_exec( $ch ) ) {
echo "Error";
}

I can't understand why it doesn't work, but all I ever get back is the
error. I have tried several proxies and ports, and they all return the
same message.

In researching the problem, I thought I was on to something when I
read that the host could have a firewall in place to block
connections. My host had, in fact, done this and required having a
dedicated IP in order to bypass the firewall. I paid for the dedicated
IP and now have it configured that way, but I'm still getting an
error!

Oh, BTW, I had it echo curl_getinfo( $ch, CURLINFO_HTTP_CODE ) in
place of the error message, but all I got back was "0", which -
obviously - is not a valid HTTP code.

Any help you can provide will be appreciated. Feel free to respond via
e-mail or the group, as I will be checking both frequently until this
is resolved.

Thanks in advance.

Tim

Re: HTTP request with proxy

am 02.10.2007 13:34:47 von Erwin Moller

Tim Arview wrote:
> Hello,
>
> I am working on a project to access a web page through a proxy. I do
> not host the script myself, but upload it to my hosting provider. The
> version of PHP on that server is 4.4.6.
>
> I have attempted using fsockopen as well as cURL to accomplish this
> task, but it won't seem to work. Here is the important bits of the
> code I am using:
>
> $ch = curl_init();
> curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
> curl_setopt( $ch, CURLOPT_PROXY, $proxy . ":" . $port );
> curl_setopt( $ch, CURLOPT_URL, $url );
> curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
> curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
> if( !curl_exec( $ch ) ) {
> echo "Error";

Hi,

Try curl_error() here to get a better errordesription.

Also, some proxies demand a username/password. Could this be the case?


> }
>
> I can't understand why it doesn't work, but all I ever get back is the
> error. I have tried several proxies and ports, and they all return the
> same message.
>
> In researching the problem, I thought I was on to something when I
> read that the host could have a firewall in place to block
> connections. My host had, in fact, done this and required having a
> dedicated IP in order to bypass the firewall. I paid for the dedicated
> IP and now have it configured that way, but I'm still getting an
> error!

Talk with your ISP about this.


>
> Oh, BTW, I had it echo curl_getinfo( $ch, CURLINFO_HTTP_CODE ) in
> place of the error message, but all I got back was "0", which -
> obviously - is not a valid HTTP code.
>
> Any help you can provide will be appreciated. Feel free to respond via
> e-mail or the group, as I will be checking both frequently until this
> is resolved.
>
> Thanks in advance.
>
> Tim
>

Good luck.
Maybe you get luckier with curl_error().

Regards,
Erwin Moller

Re: HTTP request with proxy

am 04.10.2007 02:05:00 von Manuel Lemos

Hello,

on 10/02/2007 12:10 AM Tim Arview said the following:
> Hello,
>
> I am working on a project to access a web page through a proxy. I do
> not host the script myself, but upload it to my hosting provider. The
> version of PHP on that server is 4.4.6.
>
> I have attempted using fsockopen as well as cURL to accomplish this
> task, but it won't seem to work. Here is the important bits of the
> code I am using:
>
> $ch = curl_init();
> curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
> curl_setopt( $ch, CURLOPT_PROXY, $proxy . ":" . $port );
> curl_setopt( $ch, CURLOPT_URL, $url );
> curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
> curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
> if( !curl_exec( $ch ) ) {
> echo "Error";
> }
>
> I can't understand why it doesn't work, but all I ever get back is the
> error. I have tried several proxies and ports, and they all return the
> same message.

Maybe the proxy requires authentication.

You may want to take a look at this HTTP client class. It supports
proxies and authentication too. If you still have a problem, at least
the class can output debug information with the HTTP dialog so you can
see why it fails:

http://www.phpclasses.org/httpclient


--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/