xcalibur has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

My question is an extension of this node:

http://www.perlmonks.org/?node_id=248608

I need to use a proxy to login into a website (with my userid/passwd) to post to it.

It is straightforward when one uses the "GET":

#!/usr/bin/perl use LWP::UserAgent; use strict; push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, "LocalPort" => "7000"); my $a = new LWP::UserAgent(); $a->proxy('http', 'http://ofgfw1.owfg.com:8080/'); $a->get("http://mysite.com/");

But let's say I want to use the "POST" in HTTP:Request, in something like:

my $url='mysite.com'; $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave +=> 1)); $req = HTTP::Request->new(POST => 'mysite.com/user_login.php'); $req->content_type('application/x-www-form-urlencoded'); $req->content('username=peter&&passwd=password&&login=yes'); my $res = $ua->request($req); $req = HTTP::Request->new( POST => $url . 'post_something.php' ); $req->content_type('application/x-www-form-urlencoded'); $req->content($data); $res = $ua->request( $req );

I was thinking of doing something like:

$ua->proxy('http', 'http://ofgfw1.owfg.com:8080/'); #???!!!

But my program screams!

How to implement connecting to a proxy with "POST" as opposed to "GET"?

Any hints would be much appreciated.

--

Cheers,

Peter "Excalibur"

Replies are listed 'Best First'.
Re: Force LWP to connect to a proxy for HTTP::Request POST
by Anonymous Monk on Mar 26, 2010 at 16:42 UTC
    But my program screams!

    What does it scream?

    How to implement connecting to a proxy with "POST" as opposed to "GET"?

    There is nothing special to implement. However, if your proxy for some reason denies POST or doesn't implement POST, then you need a new proxy.

      It screams only for the "POST" but works fine with the "GET"

      500 Can't connect to ofgfw1.owfg.com:8080 (Bad hostname 'ofgfw1.owfg.com')

      500 Can't connect to ofgfw1.owfg.com:8080 (Bad hostname 'ofgfw1.owfg.com')/

      Content-Type: text/plain

      Client-Date: Sat, 27 Mar 2010 00:18:14 GMT

      Client-Warning: Internal response

      The weird thing is that it works fine for "GET"

        ... $req = HTTP::Request->new(POST => 'mysite.com/user_login.php'); ...

        It seems you're not supplying a protocol here. Maybe that's the cause of your error. Personally, I would try with WWW::Mechanize and use something like the Mozilla Live HTTP Headers and Wireshark to inspect and compare the network traffic sent by the browser and your script.