on 7/5/02 7:55 AM, [EMAIL PROTECTED] purportedly said:
> HI,
>
> I am new to this mailing list as well new to Perl and Web technology,
> I am writing a script to automate upload and download a file from and to a
> web server.
> My first step is authenticate, where I need to send a POST request with
> userId, password and Instituteid
> and I will get a cookie which will contain some Id, and using that Id I need
> to upload the file as Multipart/form-data, in MIME format,
>
> I have written a script to get the cookie, but whenever I send a request I
> get an error message 302 Moved Temporarily ,but the script to authenticate
> is present in its location.
> Could any one tell me what could be the reason.
Returning 302 may be the proper response for that script, unless you wrote
the script yourself, in which case you can look at the script to see under
what conditions it would generate a 302 response. Most browsers do not show
or record in history a 302 response, so you couldn't compare browser
behavior to your script. Opera, however, has the ability to turn off
automatic redirects (like 302 responses), so you could see whether this
response is proper.
Another issue you will encounter is that if you do not bind the cookie
object to the user agent object, LWP will not return set cookies (unless you
set the cookie headers manually, but why bother?). IMHO you should do this
after creating the user agent. Move all the cookie object creation code to
the top (except extract and save), and after the LWP::UserAgent->new() line
add:
$ua->cookie_jar( $cjar_jar );
And all will be well.
> My script to get the Cookie id is
>
> use LWP::UserAgent;
> use HTTP::Request;
> use HTTP::Cookies;
>
>
> my $ua = LWP::UserAgent->new();
> my $uipwd = 'User=otc&Password=abc&Institution=xyz';
>
> my $url = $ARGV[0];
> my $request = HTTP::Request->new('POST','/cgi-bin/first.cgi');
> $request->url($url);
> $request->content_type('application/x-www-form-urlencoded');
> $request->content_length(length($uipwd));
> $request->content($uipwd);
> my $res = $ua->request($request);
>
> #$cjar = HTTP::Cookies::Netscape->new;
> $cjar = HTTP::Cookies->new;
> $cjar->extract_cookies($res);
> $cjar->save("lwpcookies.txt");
>
> print $request->as_string();
>
> if ($res->is_success) {
> print $res->content;
> } else {
> print $res->error_as_HTML;
> }
>
>
>
> Regards,
> Nitin.
>
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"