f



How Do I Use Proxy in Net:HTTP?

Can anyone tell me how the proxy is implemented in LWP:UserAgent? I have to
use a proxy in Net:HTTP, but proxy is not supported in it.


0
ir (3)
10/15/2003 6:26:03 PM
comp.lang.perl.misc 33226 articles. 1 followers. brian (1246) is leader. Post Follow

6 Replies
1895 Views

Similar Articles

[PageSpeed] 54

On Wed, 15 Oct 2003 18:26:03 GMT, "Public Interest" <ir@labranche.com>
wrote:

>Can anyone tell me how the proxy is implemented in LWP:UserAgent? 
>I have to use a proxy in Net:HTTP, but proxy is not supported in it.

$ua->proxy(['http'] => "http://$proxy:$port");
0
Helgi
10/15/2003 7:07:43 PM
"Public Interest" <ir@labranche.com> writes:

> Can anyone tell me how the proxy is implemented in LWP:UserAgent? I have to
> use a proxy in Net:HTTP, but proxy is not supported in it.

Net::HTTP support proxies just fine.  RFC 2616 explains how to do it.
You basically just provide full absolute URLs with the requests you
send.

-- 
Gisle Aas
0
gisle
10/15/2003 10:22:10 PM
Please give me a line or two showing how to use proxy..

In UserAgent it is:
$ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');

Can do use the same line in Net:Http? I don' know how use use 2616.

<gisle@activestate.com> ????
news:m3ad82rvjh.fsf@eik.i-did-not-set--mail-host-address--so-shoot-me...
> "Public Interest" <ir@labranche.com> writes:
>
> > Can anyone tell me how the proxy is implemented in LWP:UserAgent? I have
to
> > use a proxy in Net:HTTP, but proxy is not supported in it.
>
> Net::HTTP support proxies just fine.  RFC 2616 explains how to do it.
> You basically just provide full absolute URLs with the requests you
> send.
>
> -- 
> Gisle Aas


0
Public
10/19/2003 4:51:53 AM
Public Interest wrote:

>Please give me a line or two showing how to use proxy..
>
>In UserAgent it is:
>$ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');
>
>Can do use the same line in Net:Http? I don' know how use use 2616.

No. As Gisle Aas wrote, you have to do a low level connection yourself.
Thank goodness, the difference between a direct connection and a
connection via proxy is minimal. The gist is:

For a normal connection, you 
 - connect to  a host/port, and 
 - request for a URL that looks like an absolute Unix path. (= relative
to the domain root)

For a proxy connection, you
 - connect to the proxy, and
 - request for an absolute URL, including protocol ("http"), domain and
optionally, port.

Here's an example modified from the Synopsis of Net::Http, which
requests a page on a port different from the default for http, 80:

	use Net::HTTP;
	my $s = Net::HTTP->new(Host => "modperl.com", PeerPort => 9000)
 	  or die $@;
	$s->write_request(GET => "/perl_networking/errata.html");
	my($code, $mess, %h) = $s->read_response_headers;

	print "Response code: $code ($mess)\n";
	use Data::Dumper;
	print Data::Dumper->Dump([\%h], ['*headers']);
	print "\n";

	{
	    my $n = $s->read_entity_body(my $buf, 1024);
	    die "read failed: $!" unless defined $n;
	    print $buf;
	    redo if $n;
	}

Here is it again, for another URL, and modified to connect via the proxy
of my ISP (<http://proxy.pandora.be:8080>):

	use Net::HTTP;
	my $s = Net::HTTP->new(Host => "httpd.apache.org",
	  PeerAddr => 'proxy.pandora.be', PeerPort => 8080) or die $@;
	$s->write_request(GET =>
	  "http://httpd.apache.org/docs/misc/FAQ.html");
	my($code, $mess, %h) = $s->read_response_headers;

	print "Response code: $code ($mess)\n";
	use Data::Dumper;
	print Data::Dumper->Dump([\%h], ['*headers']);
	print "\n";

	{
	    my $n = $s->read_entity_body(my $buf, 1024);
	    die "read failed: $!" unless defined $n;
	    print $buf;
	    redo if $n;
	}

IMO the code to retrieve data via a proxy is actually simpler than for a
normal connection, because (almost) everything but the URL for the GET
is constant.

n.b. I think the Host property is mainly important if you encounter name
based virtual hosts, otherwise you could get pages from the wrong
domain.

-- 
	Bart.
0
Bart
10/19/2003 11:42:41 AM
Dear Master Bart,

Thank YOU.
My own code was:
 my $s = Net::HTTP->new(Host => '64.161.246.100:8080') || die $@;
 $s->write_request(GET => 'http://quote.yahoo.com', 'User-Agent' =>
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)' );

So I did not know the syntax of using proxy, because it was not said in it.

My final question on this: Why do I have to put host here? Because I put
peeradd which is proxy server, peerport and the abs url. Your said the Host
is important for virtual domain, but you already has the full url to let
httpd to know? Can I do?

> my $s = Net::HTTP->new(
>   PeerAddr => 'proxy.pandora.be', PeerPort => 8080) or die $@;
> $s->write_request(GET =>
>   "http://httpd.apache.org/docs/misc/FAQ.html");

or

> my $s = Net::HTTP->new(Host => "httpd.apache.org",
>   PeerAddr => 'proxy.pandora.be', PeerPort => 8080) or die $@;
> $s->write_request(GET =>
>   "/docs/misc/FAQ.html");


..


0
Public
10/20/2003 6:25:13 AM
One of things I don't undertand is you and I both read the same document on
Net::Http, there is no such info as what I need, but you can write a correct
code and I could not. Do you have a better documation file or a better cook
book? What you explained to me on how to use the proxy is no where found.
Don't know how you first guessed the syntax right.


0
Public
10/20/2003 6:54:13 AM
Reply:

Similar Artilces:

Net::HTTP::Proxy using one or more proxies
Hi to net/http/proxy developers, is possible to use multiple proxies in Net::HTTP::Proxy? Tips pls. Thanks and kind regards -botp Hi, In mail "Net::HTTP::Proxy using one or more proxies" "Pe=F1a, Botp" <botp@delmonte-phil.com> wrote: > is possible to use multiple proxies in Net::HTTP::Proxy? > Tips pls. In a word, No. You must use multiple Net::HTTP objects explicitly. Regards, Minero Aoki ...

Using Net::HTTP to proxy HTTPS
As far as I can tell from my experimenting, there is no way to proxy HTTPS requests using the Net::HTTP classes. My question is: can it be done? And if so, how? I've tried numerous variations, but the main gist of what I've tried is this code fragment: httpobj = Net::HTTP.new( host, port ) # this Proxy version below doesn't work to post to an HTTPS url through a proxy even though # it's supposed to have # the same methods as Net::HTTP, errors with a use_ssl is not a method # httpobj = Net::HTTP.Proxy( @proxy_host, @proxy_port, @proxy_user, @proxy_password ) httpobj...

How to use proxy in Net::HTTP, not in LWP::UserAgent?
I need some features that are in Net::HTTP but not in LWP::UserAgent. I used proxy in LWP::UserAgent, and I think LWP::UserAgent is using Net::HTTP, but I can not find how I can use proxy in Net::HTTP directly... deals@slip-12-64-108-121.mis.prserv.net (Great Deals) writes: > I need some features that are in Net::HTTP but not in LWP::UserAgent. Which feature is that? > I used proxy in LWP::UserAgent, and I think LWP::UserAgent is using > Net::HTTP, but I can not find how I can use proxy in Net::HTTP > directly... Read the HTTP spec. Or monitor how some application (like LW...

Nuby: using net/http*s* from behind a proxy server
Hey All, I've had reasonable luck using net/http from behind a proxy server here at work, but now I need to draw down SSL-encrypted pages via https. Here's my latest, unsuccessful attempt: # ------------------------------- require "uri" require "net/https" uri = URI.parse("https://appliedresearch.cancer.gov/crnportal/ directory") ghc_proxy = Net::HTTP.Proxy(PROXYSERVER, PROXYPORT) ghc_proxy.start(uri.host, uri.port) do |sess| sess.use_ssl = true puts("in block") end # ------------------------------- That gets me one of these here: c...

HTTP Proxy via HTTP Layer by Perl?
I am not sure how proxy works. The basic is it got a request then forward it. I need a perl program for doing that. There are windows, binary based proxys. However, I have to have broadband to use it, then it will cost $50 a month for only fast down, but slow up. If I have a Perl/PHP proxy, and use web server port 80, then I only need to pay $10 web hosting fee for super fast connections up and down. I searched cpan but there is none like that. I went to hotscripts. The only proxy is web based. But I need http layer so that I just enter the ip and port in browser then I am ready to go. Anyo...

Net::SSH:W32Perl Uses Net::SSH:Perl
Hi, I am a new Perl user trying to setup an SSH connection using Perl. So I first downloaded the Net::SSH:Perl package. Since I am a Windows XP user, the getpwuid function didn't work. I googled and found that Net::SSH:W32Perl solves that problem. But when i downloaded Net::SSH:W32Perl, and opened the W32Perl.pm file, i founded that it uses the Perl.pm file which uses the getpwuid function. and Thus i still get the same error: The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/Perl.pm line 110. Please help me in this issue.. Thanks alot Mazen In ar...

easy to use http proxy for windows that supports basic proxy authentication?
Will the suffering ever end?! I am searching for an easy to use http proxy for windows that supports basic proxy authentication. I've been trying quite a few, including winproxy, winroute, tinyproxy, et al, and nothing has fully worked yet... or some of them have worked TOO well (i.e. apparently assumed that I didn't need to authenticate because I was connecting from localhost, when basic proxy authentication is the thing I need to test!) All I'm trying to do is debug an app I'm writing that is using basic proxy authentication by checking that it is supplying some creden...

easy to use http proxy for windows that supports basic proxy authentication?
Will the suffering ever end?! I am searching for an easy to use http proxy for windows that supports basic proxy authentication. I've been trying quite a few, including winproxy, winroute, tinyproxy, et al, and nothing has fully worked yet... or some of them have worked TOO well (i.e. apparently assumed that I didn't need to authenticate because I was connecting from localhost, when basic proxy authentication is the thing I need to test!) All I'm trying to do is debug an app I'm writing that is using basic proxy authentication by checking that it is supplying some creden...

Using HTTP::Proxy
I am having trouble getting this to work. Can anyone tell me what I am doing wrong? This is simple test code. use HTTP::Proxy; use HTTP::Proxy::BodyFilter::simple; use HTTP::Proxy::BodyFilter::tags; use LWP::RobotUA; my $proxy = HTTP::Proxy->new; $proxy->port( 3128 ); # the classical accessors are here! $proxy->host(undef); print "post set\n"; $proxy->logmask(ALL); # you can also use your own UserAgent my $agent = LWP::RobotUA->new('my-robot/0.1', 'me@foo.com'); print "agent = $agent\n"; $proxy->agent( $agent ); $proxy->push_filter( ...

ssh issue: core not dumped: /var/core/core.sshd, cannot connect using Perl module Net::SSH::Perl
I'm getting the error logs in the /var/adm/messages files when a .NET program using the jscape.ssh.dll is trying to connect to SUN Solaris 8 server with OPENssh 4.3 p2. Issue is that this occurs from time to time. I'm also having issue when using Perl module Net::SSH::Perl with debug turned on. Connecting to svr1.mydom.com mydom.com: Reading configuration data /home/mike/.ssh/config mydom.com: Reading configuration data /etc/ssh_config mydom.com: Connecting to svr1.mydom.com, port 22. mydom.com: Remote version string: SSH-2.0-OpenSSH_4.3 mydom.com: Remote protocol version 2.0, remote...

deisng perl perl programmibng langs in perl
then liberate big war zones with notes on their download pages. -r www.thevoid1.net/ ...

net/http: using cookies
Hey everyone, I'm trying to post a form to a site using net/http. I think it works, I'm not sure, but does net/http store cookies? Because I think that's the problem: loggin in isn't very hard, but the cookies aren't stored. Does anyone know of a way to do that? -- Best regards, Chris Eidhof >From a library I use at work ... def login(username, password, domain = nil) path = 'Login' data = %Q{<?xml version="1.0" ?> <authorization> <username><![CDATA[#{username}]]></username> ...

How to use max_siz in Net:Http
max_size is included in LWP:UserAgent? How do I use max_size or similar in Net:Http? ...

Which HTTP proxy am I using and how is the traffic being routed?
Hi. In my school, all HTTP traffic has to be filtered through a proxy server, say proxy.school.edu:8080. However, it appears that my school network is linked to the Internet via a leased line from a local ISP which has its own proxy server, say proxy.isp.com:8080. I experimented with using both servers as my HTTP proxy setting in my web browser and found that both can work. I hope to know exactly which HTTP proxy am I using anyway? I'm surprised that I can use a proxy server outside of my school network over at the ISP side and I wonder how my HTTP traffic managed to get...

Web resources about - How Do I Use Proxy in Net:HTTP? - comp.lang.perl.misc

Resources last updated: 1/24/2016 3:44:03 AM