in reply to File upload with LWP::UserAgent

URL missing is not a webserver response, it signifies that you didn't pass the URL:
my $request = HTTP::Request->new(POST 'http://example.com', Content_Ty +pe => 'multipart/form-data', Content => [file_0 => ['options2.txt']]) +;

You're missing => after POST. Which probably explains the immediate error: POST 'http://..' is seen as a function call (from HTTP:::Request::Common) instead of a string.

AFAIK the content should be added using the content method, not as an argument to the constructor (since constructor arguments are all parsed as headers. See HTTP::Request

Anyway, using WWW::Mechanize will probably be easier and make your code a bit more robust.

Replies are listed 'Best First'.
Re^2: File upload with LWP::UserAgent
by PerlRob (Sexton) on Jun 13, 2008 at 02:11 UTC
    Thanks for suggesting WWW::Mechanize. I'm getting a little further, but I think my problem now is that I can't get cookies working. When I authenticate, the appropriate page is returned, but the next page I request prompts me to log in again. Here's my code:
    use HTTP::Cookies; use WWW::Mechanize; my $cj = HTTP::Cookies->new( autosave => 1, ignore_discard => 1 ); my $mech = WWW::Mechanize->new( cookie_jar => $cj ); $mech->get( 'http://example.com/login.action' ); if ($mech->success()) { $mech->submit_form( form_name => 'loginform', fields => { os_usern +ame => 'username', os_password => 'password' } ); } if ($mech->success()) { $mech->follow_link( text => 'Training'); # This is where I get red +irected to the login page again! }

    Am I using cookies improperly, or is there some other problem with my code?
      I figured it out. The login form has a checkbox for remembering your username/password (as login forms often do). I simply had to use the tick() method to make sure that box was checked so that I could receive the login cookie and access subsequent pages.

      Thanks again for suggesting WWW::Mechanize!