Home > Archive > PERL Miscellaneous > August 2007 > problems with LWP & HTTP
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problems with LWP & HTTP
|
|
| stephenc 2007-08-14, 7:03 pm |
| Hi
I am trying to log into a secur site using this:
use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);
my $ua = new LWP::UserAgent;
my $req = POST 'https://www.secure.********.com.au/Cardlink/
LoginServlet',
[ 'UserID' => '*********',
'Password' => '********',
'Submit' => 'Submit'
];
print $req->as_string;
my $res = $ua->request($req)
print $response->content();
When I run it at the prompt it hangs after printing print $req-
>as_string;
I'm a bit out of my depth. Anyone know how i can get this to return
the page I am lloking for?
| |
| Bob Walton 2007-08-14, 7:03 pm |
| stephenc wrote:
....[color=darkred]
> I am trying to log into a secur site using this:
>
> use LWP;
> use Crypt::SSLeay;
> use HTTP::Request::Common qw(POST);
>
> my $ua = new LWP::UserAgent;
>
>
>
>
> my $req = POST 'https://www.secure.********.com.au/Cardlink/
> LoginServlet',
> [ 'UserID' => '*********',
> 'Password' => '********',
> 'Submit' => 'Submit'
> ];
>
> print $req->as_string;
> my $res = $ua->request($req)
> print $response->content();
>
> When I run it at the prompt it hangs after printing print $req-
....
When I try it, your code doesn't even compile. Please try again, being
sure to copy/paste your code rather than typing it in.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
| |
| Petr Vileta 2007-08-14, 10:04 pm |
| stephenc wrote:
> Hi
>
> I am trying to log into a secur site using this:
>
> use LWP;
> use Crypt::SSLeay;
> use HTTP::Request::Common qw(POST);
>
> my $ua = new LWP::UserAgent;
>
>
>
>
> my $req = POST 'https://www.secure.********.com.au/Cardlink/
> LoginServlet',
> [ 'UserID' => '*********',
> 'Password' => '********',
> 'Submit' => 'Submit'
> ];
>
> print $req->as_string;
> my $res = $ua->request($req)
> print $response->content();
>
last line should be
print $res->content();
Isn't true?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
| |
| stephenc 2007-08-15, 4:10 am |
| OK, this code does compile but I have had to change my user id and
pasword for obvious reasons:
use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);
my $ua = new LWP::UserAgent;
my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
LoginServlet',
[ 'UserID' => 'abshidf',
'Password' => 'oddhfhg',
'Submit' => 'Submit'
];
print $req->as_string;
my $res = $ua->request($req);
print $res->content();
It still hangs!
On Aug 15, 9:55 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
> stephenc wrote:
>
>
>
>
>
>
> last line should be
>
> print $res->content();
>
> Isn't true?
>
> --
>
> Petr Vileta, Czech republic
> (My server rejects all messages from Yahoo and Hotmail. Send me your mail
> from another non-spammer site please.)- Hide quoted text -
>
> - Show quoted text -
| |
| Narthring 2007-08-15, 7:08 pm |
| The UserAgent isn't allowing redirection from a POST. This should fix
the problem.
use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);
my $ua = new LWP::UserAgent;
push @{$ua->requests_redirectable}, 'POST'; #allow redirection
from POST
my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
LoginServlet',
[ 'UserID' => 'abshidf',
'Password' => 'oddhfhg',
'Submit' => 'Submit'
];
print $req->as_string;
my $res = $ua->request($req);
print $res->content();
On Aug 15, 1:58 am, stephenc <m...@bymouth.com> wrote:[color=darkred]
> OK, this code does compile but I have had to change my user id and
> pasword for obvious reasons:
>
> use LWP;
> use Crypt::SSLeay;
> use HTTP::Request::Common qw(POST);
>
> my $ua = new LWP::UserAgent;
>
> my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
> LoginServlet',
> [ 'UserID' => 'abshidf',
> 'Password' => 'oddhfhg',
> 'Submit' => 'Submit'
> ];
>
> print $req->as_string;
> my $res = $ua->request($req);
> print $res->content();
>
> It still hangs!
>
> On Aug 15, 9:55 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
| |
| Petr Vileta 2007-08-15, 7:08 pm |
| stephenc wrote:
> OK, this code does compile but I have had to change my user id and
> pasword for obvious reasons:
>
> use LWP;
> use Crypt::SSLeay;
> use HTTP::Request::Common qw(POST);
>
> my $ua = new LWP::UserAgent;
>
>
>
>
> my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
> LoginServlet',
Try this script. Maybe this can help you to find reason ;-)
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
print "Content-type: text/html\n\n";
# don't forget to set right values in next line
my $params='UserID=abc&Password=abc&Submit=Submit';
my $ua = LWP::UserAgent->new(timeout => 30);
my $req = HTTP::Request->new(POST =>
'https://www.secure.cardlink.com.au/Cardlink/LoginServlet');
$req->headers->header(Accept => '*/*');
$req->headers->header(Connection => "Keep-Alive");
$req->headers->header(Accept_language => "en");
$req->headers->header(Cache_Control => 'no-cache');
$req->content_type('application/x-www-form-urlencoded');
$req->content($params);
my $res = $ua->request($req);
if ($res->code != 200)
{
print "<html><body>Error: ",$res->code," ",$res->message,"<br>",
"Response:<br>",
"<nobr> Message: $res->{_msg}</nobr><br>",
"<nobr> Protocol: $res->{_protocol}</nobr><br>",
"<nobr> Return code: $res->{_rc}</nobr><br>",
"Response headers:<br>";
foreach (sort keys %{$res->{_headers}})
{
print "<nobr> $_: $res->{_headers}->{$_}</nobr><br>";
}
print "<br><br>Page Content:<br>$res->content" if($res->content);
print "</body></html>";
}
else
{
print $res->content;
}
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
| |
| stephenc 2007-08-24, 7:07 pm |
| On Aug 16, 1:07 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
> stephenc wrote:
>
>
>
>
> Try this script. Maybe this can help you to find reason ;-)
>
> #!/usr/bin/perl -w
> use strict;
> use LWP::UserAgent;
>
> print "Content-type: text/html\n\n";
>
> # don't forget to set right values in next line
> my $params='UserID=abc&Password=abc&Submit=Submit';
>
> my $ua = LWP::UserAgent->new(timeout => 30);
> my $req = HTTP::Request->new(POST =>
> 'https://www.secure.cardlink.com.au/Cardlink/LoginServlet');
> $req->headers->header(Accept => '*/*');
> $req->headers->header(Connection => "Keep-Alive");
> $req->headers->header(Accept_language => "en");
> $req->headers->header(Cache_Control => 'no-cache');
> $req->content_type('application/x-www-form-urlencoded');
> $req->content($params);
> my $res = $ua->request($req);
> if ($res->code != 200)
> {
> print "<html><body>Error: ",$res->code," ",$res->message,"<br>",
> "Response:<br>",
> "<nobr> Message: $res->{_msg}</nobr><br>",
> "<nobr> Protocol: $res->{_protocol}</nobr><br>",
> "<nobr> Return code: $res->{_rc}</nobr><br>",
> "Response headers:<br>";
> foreach (sort keys %{$res->{_headers}})
> {
> print "<nobr> $_: $res->{_headers}->{$_}</nobr><br>";
> }
> print "<br><br>Page Content:<br>$res->content" if($res->content);
> print "</body></html>";
> }
> else
> {
> print $res->content;
> }
>
> --
>
> Petr Vileta, Czech republic
> (My server rejects all messages from Yahoo and Hotmail. Send me your mail
> from another non-spammer site please.)
I tried this (having changed the parameters but it still hung at this
point:
C:\eventOrganizerV2>d.pl
Content-type: text/html
I tried enabling cookies and opening the preceding page to see if I
pickedany up but it didn't help.
Any further suggestions?
| |
| stephenc 2007-08-28, 8:24 am |
| On Aug 15, 11:57 pm, Narthring <Narthr...@gmail.com> wrote:
> The UserAgent isn't allowing redirection from a POST. This should fix
> the problem.
>
> useLWP;
> use Crypt::SSLeay;
> use HTTP::Request::Common qw(POST);
>
> my $ua = newLWP::UserAgent;
> push @{$ua->requests_redirectable}, 'POST'; #allow redirection
> from POST
>
> my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
> LoginServlet',
> [ 'UserID' => 'abshidf',
> 'Password' => 'oddhfhg',
> 'Submit' => 'Submit'
> ];
>
> print $req->as_string;
> my $res = $ua->request($req);
> print $res->content();
>
> On Aug 15, 1:58 am, stephenc <m...@bymouth.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
Hi
I tried that and also enabling cookies and go through the opening page
but it still hangs as the second request. This is te code:
# clearCard.pl
use strict;
use LWP;
use LWP::UserAgent;
use Crypt::SSLeay;
my $browser = LWP::UserAgent -> new;
push @{$browser->requests_redirectable}, 'POST';
$browser->cookie_jar({});
my $response = $browser -> get ('https://www.secure.cardlink.com.au/
Cardlink/login.jsp');
#print $response->content();
print "to here\n";
$response = $browser -> post (
'https://www.secure.cardlink.com.au/Cardlink/LoginServlet',
[
'UserID' => 'abcgsre',
'Password' => 'hfyretsg',
'Submit' => 'Submit'
],
);
$response->is_success or
die "Login failed: ", $response->status_line, "\n";
#print $response->content();
Any further ideas?
|
|
|
|
|