Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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: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
This is my receiving 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(); }
#!/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>");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: POSTing from one script to another
by z3d (Scribe) on May 05, 2004 at 11:45 UTC | |
by Anonymous Monk on May 05, 2004 at 12:27 UTC | |
|
Re: POSTing from one script to another
by matija (Priest) on May 05, 2004 at 11:45 UTC | |
by Anonymous Monk on May 05, 2004 at 12:23 UTC | |
by matija (Priest) on May 05, 2004 at 13:19 UTC | |
by Anonymous Monk on May 05, 2004 at 15:24 UTC | |
by Anonymous Monk on May 05, 2004 at 15:26 UTC |