C
Calvine Chew
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 response
501 syntax error
501 syntax error
###################
Both sending and receiving scripts are on the same server. 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 qwstandard);
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-data">
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 server code:
###################
#!/usr/bin/perl
use CGI qwstandard);
$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>");
###################
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 response
501 syntax error
501 syntax error
###################
Both sending and receiving scripts are on the same server. 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 qwstandard);
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-data">
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 server code:
###################
#!/usr/bin/perl
use CGI qwstandard);
$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>");
###################