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&section=LWP_Test"; my $response = $ua->get($url); if ($response->is_success) { print $response->content; } else { print STDERR $response->status_line; }

In reply to missing credentials when uploading file with POST by helix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.