Help using a proxy

S

Shan

I use Privoxy an tor. The settings for my firefox web browser to
correctly use the proxy are as follows:

HTTP Proxy: localhost Port: 8118
SLS Proxy: localhost Port: 8118
FTP Proxy: localhost Port: 8118
Gopher Proxy: localhost Port: 8118


I want to know how I can use a proxy with perl

my $ua = LWP::UserAgent->new;
$ua->timeout(20);
$ua->env_proxy; # I dont know what to modify so that proxy works.
my $response = $ua->get('http://www.helpme.com');
if ($response->is_success)
{
my $html=$response->content;
}


I would appreciate it if you could help me use a proxy successfully
with perl. Thank you in advance.
 
J

J. Gleixner

Shan said:
I use Privoxy an tor. The settings for my firefox web browser to
correctly use the proxy are as follows:

HTTP Proxy: localhost Port: 8118
SLS Proxy: localhost Port: 8118
FTP Proxy: localhost Port: 8118
Gopher Proxy: localhost Port: 8118


I want to know how I can use a proxy with perl

Actually, it'd be how to have LWP::UserAgent use a proxy.
my $ua = LWP::UserAgent->new;
$ua->timeout(20);
$ua->env_proxy; # I dont know what to modify so that proxy works.
my $response = $ua->get('http://www.helpme.com');
if ($response->is_success)
{
my $html=$response->content;
}


I would appreciate it if you could help me use a proxy successfully
with perl. Thank you in advance.

It seems to be well documented.

From perldoc LWP::UserAgent:

$ua->env_proxy
Load proxy settings from *_proxy environment variables. You might
specify proxies like this (sh-syntax):
[...]

or from perldoc lwpcook:

You should initialize your proxy setting before you start sending
requests:

use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->env_proxy; # initialize from environment variables
# or
$ua->proxy[...]


It's up to you. You may use your environment variables, by calling
env_proxy(), or set what you need using proxy().

To include the port, add it to the end, separated with a ':". e.g.
'localhost:8118'.
 
S

Shan

I tried doing

$ua->proxy(['http','gopher','ftp','ssl'], 'localhost:8118');

But this does not work. I get a message saying

501 Protocol scheme 'localhost' is not supported


I don't knwo what to do. Will someone please help me with the code?
 
I

Ian Wilson

Shan said:
I tried doing

$ua->proxy(['http','gopher','ftp','ssl'], 'localhost:8118');

But this does not work. I get a message saying

501 Protocol scheme 'localhost' is not supported

Well clearly it was expecting the name of a network protocol, you know,
telnet, gopher, that kind of thing.
I don't knwo what to do.

I just read the documentation, the answer is there.
perldoc lwp::useragent
Will someone please help me with the code?

If you read the above, you will get to a bit where it says

$ua->proxy(...)
Set/retrieve proxy URL for a scheme:

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

where I have replaced the answer with XXXXXXX so that you may experience
the joy of perldoc for yourself :)
 
I

Ian Wilson

Shan said:
I did read perldoc lwp::useragent

Good, you could have saved me having to guess by saying what
documentation you consulted (unless you did earlier and I missed it?)
$ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');

I still can't get it to work.

It would be helpful if quote some context (relevant parts of prior
discussion) and give the actual error messages.

Earlier you said
I tried doing
$ua->proxy(['http','gopher','ftp','ssl'], 'localhost:8118');
But this does not work. I get a message saying
501 Protocol scheme 'localhost' is not supported

Which was good because you showed some of *your* code and gave the text
of the error message. This time you did neither.


Did you notice there is a significant difference between perldoc's
$ua->proxy(['http','gopher','ftp','ssl'], 'localhost:8118');
and your
$ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');

let's break that down

$ua Your user agent object
->proxy(...) A method that tells the user agent to use a proxy
['http' ...] A list of *protocols* to be proxied

The next part is a URL in the documentation, this particular URL has
three parts: a protocol (http://), a hostname (proxy.sn.no) and a port
number :)8001).

You have only two parts of the URL, a hostname(localhost) and a port
:)8118). You omitted the first of the three parts of the URL.

If this is the cause of your problem, please try to learn how to read
the perl documentation carefully and diligently, I find it works well
most of the time for me.

If this isn't the cause of your problem then I commend this document to
you: http://www.catb.org/~esr/faqs/smart-questions.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top