>I'm trying to use HTTP::Cookies and LWP::UserAgent to fake a real user HTTP
>request.  When executing this script from a browser, I want to set the
>cookies that the website normally would and load the page that the website
>normally would also.  I can't get the cookie part to work.  I'm able to 
>send
>a 'fake' referer, but I'm not able to get the cookie information.  Could
>someone take a look at my script and tell me what's wrong?  I'm sure it's
>all messed up, but I'm so frustrated with it that I don't know what to do.
>The examples I found in CPAN are terrible.
>
>
>My script:
>
>#!c:\perl -w
>
>use strict;
>use CGI::Carp qw(fatalsToBrowser);
>
>use HTTP::Request::Common qw(GET);
>use HTTP::Cookies;
>use LWP::UserAgent;
>
>my $cookieFile = "lwpcookies.txt";
>my $ua = new LWP::UserAgent;
>
>$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; DigExt)');
>my $cookie_jar = HTTP::Cookies->new( File => "$cookieFile", AutoSave =>
>1, );
>
># the test script we are GETting prints out the referer and query string 
>and
>sets a cookie
>my $req = GET 'http://www.globalnamespace.com/sample/test.pl'; #this is my
>own test script
>$req->push_header(REFERER => 'http://www.somesite.com/');
>my $response = $ua->request($req)->as_string;
>$cookie_jar->extract_cookies($response);
>
>#print "Content-type: text/html\n\n";
>
>print $response , "<br>\n";
>
>exit;
>
>
>
>Here is my error I'm getting when running the script:
>
>Software error:
>Can't locate object method "_header" via package "HTTP/1.0 200 OK
>Date: Wed, 04 Sep 2002 15:58:18 GMT
>Server: Microsoft-IIS/5.0
>Content-Type: text/html
>Client-Date: Wed, 04 Sep 2002 15:58:18 GMT
>Client-Peer: xx.xx.xxx.xxx:80
>Set-Cookie: mycookie=set; domain=.globalnamespace.com; path=/;
>
>referer = http://www.somesite.com/<br>
>query string = <br>
>
>" (perhaps you forgot to load "HTTP/1.0 200 OK
>Date: Wed, 04 Sep 2002 15:58:18 GMT
>Server: Microsoft-IIS/5.0
>Content-Type: text/html
>Client-Date: Wed, 04 Sep 2002 15:58:18 GMT
>Client-Peer: xx.xx.xxx.xxx:80
>Set-Cookie: mycookie=set; domain=.globalnamespace.com; path=/;
>
>referer = http://www.somesite.com/<br>
>query string = <br>
>
>"?) at C:/Perl/site/lib/HTTP/Cookies.pm line 244.
>
>For help, please send mail to this site's webmaster, giving this error
>message and the time and date of the error.

I can see one really big problem here, that's that you're using MS-IIS.
but since you may not be able to fix that...
instead of using modules to do the work of making headers, referrers, 
cookies, etc, try rolling your own, you'll then know if it's the modules.

a specific web-get I wrote. I needed toset a cookie for it to work. not that 
you should enurl() anything if you're not sure it'll go throught right.
============================
use IO::Socket;
use CGI::Enurl;

$uagent="trade route automator";
$cookie="userpass=$email%2B$pass";

$i=0;
while($i<@ports){
$document="rsmove.php?engage=1&destination=$ports[$i]";
myconnect();
$document="traderoute.php?engage=$trnum[$i]&tr_repeat=$repeats";
myconnect();
$i++;
}

sub myconnect(){
        $remote = IO::Socket::INET->new( Proto     => "tcp",
                                         PeerAddr  => "$webadd",
                                         PeerPort  => "http(80)",
                                         );
        unless ($remote) { die "cannot connect to main daemon" }
        $remote->autoflush(1);

print $remote "GET /$BNdir/$document HTTP/1.0\nUser-Agent: $uagent\nCookie: 
$cookie\n\n";
        while (<$remote>){print;}
        close $remote;
}
======================

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to