I am trying to post data to a form (incuding a file upload).

The code works fine under Active Perl in windows, but I am now generating a file from a unix box.
The issue is when I run the code under unix I get a response 302 (Redirect loop detected) and the post doesn't occur.
Here is the primary code (all variables have been initialized to the proper values, and the use statements are all in place)

my $ua = LWP::UserAgent->new; # Allow post redirects to happen push @{ $ua->requests_redirectable }, 'POST'; my $result = $ua->request(POST $PostURL, Content_Type => 'form-data', Content => [ user => $UserID, password => $Password, trk_code => $TheTrackCode, upfile => [$UploadFile], ]); if ($result->is_success) { # means we got a success message back my $ReturnText = $result->content(); if (index($ReturnText, "You successfully uploaded file") > -1) { print "Upload succeeded\n"; $ReturnVal = 1; } else { print "Upload failed\n$ReturnText\n"; } } else { print "ERROR OCCURED (Code was " . $result->code() . ")\n"; my $ReturnText = $result->content(); print "Return Text was\n$ReturnText\n"; }
is_succes never gets set and I always get a 302 result even though I have added post to the requests_redirectable array.
What am I doing wrong here.
I have also tried allowing cookies just in case, but that is not the issue (I wrote the script it is attaching to and there are no cookies there)

The 302 is technically correct as it is a scriptalias cgi on apache that is being posted to, but I thought requests_redirectable was supposed to allow it to post properly.

TIA for any help you can offer. (sorry for the long post, but I wanted to give any info needed)


In reply to HTTP form Post, Getting redirect response by dougis

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.