I've been trying to get a script to post to another script for some time now but to no avail! Sending the LWP POST request to the receiving script and printing out the request/results, I get the following:
POST http://llc.compsys.org/up.cgi Content-Length: 177 Content-Type: multipart/form-data; boundary=xYzZY --xYzZY Content-Disposition: form- +data; name="upload"; filename="success.txt" Content-Length: 36 Content-Type: text/plain IT WORKED!!! 5th May 2004 11:24am --xYzZY-- It didn't work. 501 (Not Implemented) syntax error Content-Type: text/ +plain Client-Date: Wed, 05 May 2004 03:37:10 GMT Client-Warning: Internal re +sponse 501 syntax error 501 syntax error
Both sending and receiving scripts can be on the same server or 2 separate servers, and will generate the same error. I'm a relative newbie to Perl so I desperately need help on this! Any URLs or FAQs I can refer to to get more info on my troubles? Is it a Perl problem or a webserver one? Much appreciated in advance! Below is my POSTer code:
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use lib 'modules'; use LWP::UserAgent 2.031; use HTTP::Request::Common 1.22 qw/POST/; my $ua= LWP::UserAgent->new(); my $url = "http://llc.compsys.org/up.cgi"; my $fullpath_filename = param("upload"); my $filename = lc($fullpath_filename); $filename =~ s/.*[\/\\](.*)/$1/; print (header()); print (start_html( -title => 'Upload' )); if (!$filename) { print ("No file specified.<br>\n"); print qq~ <form action="upload.cgi" method="post" enctype="multipart/form-dat +a"> File upload: <input type="file" name="upload" size="60"><br> <br> <input type="submit" name="Submit" value="Upload"> </form> </body></html> ~; } else { open UPLOADFILE, ">$filename"; binmode(UPLOADFILE); while ( <$fullpath_filename> ){ print UPLOADFILE; } close UPLOADFILE; print "$filename uploaded!<br>"; my $fullpath = $ENV{'DOCUMENT_ROOT'}."/cgi-bin/$filename"; print "FULLPATH = $fullpath<br>"; print "Above file exists!<br><br>" if -e $fullpath; print "Above file does not exist!<br><br>" if !-e $fullpath; my $request=POST $url , Content_Type=>'form-data', Content => [upload=>[$filename]]; print $request->as_string; print "<br><br>"; my $results=$ua->request($request); if($results->is_success){ print "It's good!\n"; print $results->as_string; print "<br><br>"; } else { print "It didn't work.\n"; print $results->as_string; print "<br><br>"; print $results->status_line(); }
This is my receiving code:
#!/usr/bin/perl use CGI qw(:standard); $filename = param("upload"); $filename =~ s/.*[\/\\](.*)/$1/; $upload_filehandle = param("upload"); print (header()); print (start_html( -title => 'Upload' )); if (!$filename) { print ("No file specified.<br>\n"); } else { $filename = lc($filename); open UPLOADFILE, ">$filename"; binmode(UPLOADFILE); while ( <$upload_filehandle> ){ print UPLOADFILE; } close UPLOADFILE; print ("<b>$filename</b> upload successful!<br>\n"); } print ("</BODY>\n</HTML>");

In reply to POSTing from one script to another by Anonymous Monk

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.