helix has asked for the wisdom of the Perl Monks concerning the following question:
Hey Monks,
I want to upload a file to a webserver, which needs authentication. Seems, as if the UserAgent does not set the credentials (because it works when I turn off server-side authentication).
BTW, the second example works and shows, that the credentials are ok.
What do I miss? Can anymonk help?
Helix# ----- # http post, file upload # # This does NOT work use LWP::UserAgent; use HTTP::Request::Common; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->credentials("10.1.1.11:11111", "ups", "username", "password"); my $filename = "hello.txt"; my $temp_filename = "ksjbgfvksbvkns.tmp"; my $req = POST ("http://10.1.1.11:11111/put_test_blob.s2w", Content_Type => 'form-data', Content => [ fname => $temp_filename, hostname => 'lxtest1', section => 'LWP_Test', name => $filename, $temp_filename => ["$filename"], ]); my $result = $ua->request($req); print $result->as_string() , "\n"; print $result->status_line(), "\n"; # ----- # http get # # This works! use LWP::UserAgent; use URI::Escape; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->credentials("10.1.1.11:11111", "ups", "username", "password"); my $url = "http://10.1.1.111:11111/put_test_value.s2w?hostname=testhos +t§ion=LWP_Test"; my $response = $ua->get($url); if ($response->is_success) { print $response->content; } else { print STDERR $response->status_line; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: missing credentials when uploading file with POST
by zentara (Cardinal) on Apr 25, 2007 at 13:27 UTC | |
by helix (Initiate) on Apr 26, 2007 at 06:48 UTC | |
|
Re: missing credentials when uploading file with POST
by Anonymous Monk on Apr 25, 2007 at 13:11 UTC |