At 10:03 AM 1/25/00 -0500, you wrote:
>Did you get any help with this question? If so can you forward me the
>best response. I am in a similar situation.
>
>thanks heaps!!!
>
>
Rande,
Didnt get any help... but it finaly started working for me. (atleast
setting and sending cookies) One key thing i noticed was its nescessary
to keep Netscape closed while your running the script.
What I was actualy attempting to do is automate download from mp3.com.
In the end I failed. I cant quite figure out why. MP3.com doesn't like
one of ID the cookies it set while I was running Netscape, and has problems
with the email cookie (something about a control character). These strange
problems have left me clueless and frustrated. It is my suspicion that mp3.com
is comparing the data it set in those cookies to what it knows about my browser
that isn't evident in the headers (how else would it work for Netscape, yet not
for an identical request with my script?) or something equaly as sneaky.
I don't know enough about what a server can know about a client to figure
out how
mp3.com knows the diffrence between those requests, and I've invested enough
time
already. IF ANYONE HAS ANY THEORYS BEHIND WHATS GOING ON HERE, *please* let
me know.
Your welcome to try out the script for yourself. Its also a decent debuging
tool for
HTTP:cookie stuff as it prints out the request, response and state of cookie
jar before
and after the request.
oh yeah .. one other thing. i found it nescessary to include the line:
$cookie_jar->add_cookie_header($req);
to get the cookie to show up in the request headers, even though I think
the UserAgent is suposed to handle this automaticaly.
Watson
the code ive been using most recently to test follows:
------------------------------------------------------
#!/mit/perl5/perl
use LWP::UserAgent;
use HTTP::Cookies;
#****SETUP*****
$ua = new LWP::UserAgent;
$ua->agent("Mozilla/4.5 [en] (Win98; U)");
$cookie_jar = HTTP::Cookies::Netscape->new(
File => 'C:\Program
Files\Communications\Netscape\Users\me\cookies.txt',
AutoSave => 1,
);
$ua->cookie_jar($cookie_jar);
@requests = (
#the adress of a particular song (it works in netscape!)
'http://chooser.mp3.com/cgi-bin/play/play.cgi/AAIAQuBJBADABG5vcm3CBGV4dHJDMN
qIOLAu9dAWIDe9schFn2GyfqM-/breath.mp3'
);
#********************
sub makerequest {
#what to get
$download_link = shift @_;
$req = new HTTP::Request 'GET' => $download_link;
$req->header('Accept' => 'image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, image/png, */*');
$req->header('Accept_Charset' => 'iso-8859-1,*,utf-8');
$req->header('Accept_ENCODING' => 'gzip');
$req->header('Accept_LANGUAGE' => 'en');
$cookie_jar->add_cookie_header($req);
}
sub cookie_scan_cb { # call back
print OUT "version: $_[0]<br>";
print OUT " key: $_[1]<br>";
print OUT "val: $_[2]<br>";
print OUT "path: $_[3]<br>";
print OUT "domain: $_[4]<br>";
#print OUT "port: $_[5]<br>";
print OUT "path_spec: $_[6]<br>";
print OUT "secure: $_[7]<br>";
print OUT "expires: $_[8]<br>";
print OUT "discard: $_[9]<br><br><hr>";
}
#******************
$count = 1;
foreach (@requests) {
open (OUT, ">cookie_results_" . $count . '.html') or die "Can't open output
for writing\n";
$count++;
#current cookie status
print OUT "<hr><h2>State of the Cookie Jar:</h2>";
$cookie_jar->scan( \&cookie_scan_cb);
#construct the request
&makerequest($_);
#print request
print OUT "<h2>The Request:</h2>";
print OUT $req->as_string() . "<hr>";
# send request
$res = $ua->request($req);
# check the outcome
if ($res->is_success) {
print OUT "<h2>Response</h2>" . $res->as_string();
#replace is_string with this if you just want to see content: ->content;
} else {
print OUT "Error: " . $res->status_line . "\n";
}
#cookie status after request
print OUT "<hr><h2>State of the Cookie Jar after request:</h2>";
$cookie_jar->scan( \&cookie_scan_cb);
close (OUT);
}