Forum Moderators: coopster & phranque

Message Too Old, No Replies

Connect through Proxy

Works with win32, not on Unix ?

         

Damian

12:18 pm on Jan 24, 2002 (gmt 0)

10+ Year Member



The following works for me on my local machine (win32, apache 1.3.20) but not on my Unix/Apache (1.3.11) server:

my $ua = new LWP::UserAgent;
if ($useproxy) {

if ($use_randomproxy) {
&GetProxy;
$ua->proxy("http","$randomproxy");}
else {$ua->proxy("http","$defaultproxy"); }
}

Both $randomproxy and $defaultproxy contain [the_proxy_name:port_to_use...]
The response on the server is 501 when trying to go through a proxy , method not implemented. The log file doesn't show any errors.

Could this have to do with a missing or different module, apache version or am I missing something really simple ?

Brett_Tabke

12:49 pm on Jan 24, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Maybe this will inspire. (cut & paste from what I use)...

$proxyport ="8000";
$proxyadr ="1.2.3.4";#ip
$proxyadr ="http://$proxyadr:$proxyport/";

sub grab_www_page {
my $url = shift;
my $doc ="";
my $www_error =0;
my $status =0;
my $ct =0;

if (!$ouragent) {
$ouragent= 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0)';
}

my $ua = new LWP::UserAgent;
$ua->proxy('http', $proxyadr) if length($proxyadr) >4;
$ua->timeout(45);
$ua->agent($ouragent);
my $req = HTTP::Request->new(GET => $url);
$req->referer($refer) if $refer;
my $res = $ua->request($req);

$realurl = $res->request->url;
$doc = $res->content;
$ct = $res->content_type;

if ($res->is_success) {
$status = $res->code();
$www_error =0;
}
else {
$status = $res->code();
$www_error =1;
}
return($doc,$ct,$status,$www_error,$realurl)
}

Damian

2:41 pm on Jan 24, 2002 (gmt 0)

10+ Year Member



Thanks Brett !
I used your example to make a new sub and solved my problem, now works on both machines. Don't know why though...maybe something to do with the double quotes (") I used.

cerberos76

9:05 pm on Feb 7, 2002 (gmt 0)



Guys,
have you (or anyonelse) written anything for connecting through proxy via IO:SOCKET ?

I dont' have and cannot install LWP modules on the server on which I wish to use a script via an http proxy.
Any help would be appreciated

Damian

10:19 pm on Feb 7, 2002 (gmt 0)

10+ Year Member



Cerberos, sorry can't help you with IO:Socket.
Maybe you could just use the .pm files from the LWP module, ie. upload those to your scripts folder and call them there ?