In my WWW:Mechanize script below, can someone please advice why am i getting 
proxy issue. when the same proxy is working fine with LWP::UserAgent in a 
different script. (both scripts are given below)

thank you.
Rajeev



________________________________
 From: Rajeev Prasad <rp.ne...@yahoo.com>
To: perl list <beginners@perl.org> 
Sent: Tuesday, November 22, 2011 3:43 PM
Subject: using WWW::Mechanize thru proxy to https(SSL) with website/form 
authentication,  proxy error!!
 
Here is the prob description in short:


1.    post your url in browser: https://myrel/files/file.doc
2.    you get a logon page (URL still looking same)
3.    enter field names:  username/password
4.    press 'ok' button (name = bsubmit)

    after successful login:
5.    you get new page:    https://myurl/pagSuccess/
6.    you have to click 'ok'  ( field name = successbtn ) on this page now to 
go back to where you wanted to go...
7.    then you get a firefox dialog: 
        where you have to select (radio button) 'Save File'
        press ok
8.    you are done!!! (saves the file to default location)



here is the script so far:


#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize;

#print "Content-type: text/html\n\n";

my $username = "myid";
my $password = "mypass";
my $outfile = "testout.doc";
$ENV{HTTPS_PROXY} = 'http://myproxy:8080';

my $mech = WWW::Mechanize->new(noproxy =>'0');

my $url = 'https://myurl/files/file.doc';

$mech->get($url);
$mech->form_name('frmLogin');
$mech->field(username => "$username");
$mech->field(password => "$password");
$mech->click('bsubmit');

$mech->click('successbtn');    # here i am hoping this will click the 'ok' 
button the next page

my $response = $mech->content();

open(OUTFILE, ">$outfile");
print OUTFILE "$response";
close(OUTFILE);


error i am getting:

Error GETing https://myurl/files/file.doc: proxy connect failed: PROXY ERROR 
HEADER, could be non-SSL URL:
HTTP/1.0 504 Gateway Time-out
Server: squid/
Date: 
Content-Type: text/html
Content-Length: 1117
X-Squid-Error: ERR_CONNECT_FAIL 238
...
...





but the following works thru SAME proxy(it fails to do any form based 
authentication i guess)???

#!/usr/bin/perl
use strict;
use warnings;
use LWP;

my $ua = LWP::UserAgent->new;
my $agent = "my-lwp agent";
$ua->agent($agent);
$ENV{HTTPS_PROXY} = 'http://myproxy:8080';
$ENV{HTTP_PROXY} = 'http://myproxy:8080';

my $req = HTTP::Request->new(GET => 'https://mail.yahoo.com');
$req->content_type('text/html');
$req->protocol('HTTP/1.0');

my $response = $ua->request($req);
 if ($response->is_success) {
     print "1 success\n";
 }
 else {
    print "1 error\n";
 }
print $response->status_line;

Reply via email to