Results 1 to 1 of 1
I want to write my own perl module for sending multipart/form-data to a website. In common, I write a scalar string, that consists all data to send to a server. ...
- 04-27-2010 #1Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
Multipart/form-data is missed by php-script
I want to write my own perl module for sending multipart/form-data to a website. In common, I write a scalar string, that consists all data to send to a server. It's look like
as you can ses, an $Instance is a hash refrerence, which stores parsed URL and host. My php-script just displays a POST-data:Code:sub __prepareContent { my $Instance = shift; my $hdrs_as_string; $hdrs_as_string = "POST ".$Instance->{requestPath}." HTTP/1.1 Host: ".$Instance->{host}." User-Agent: PostMultipart_Simple ver-$VERSION Accept: text/plain Accept-Language: en-us Accept-Charset: utf-8 Content-Type: multipart/form-data; boundary=$boundary Content-Length:"; my $content = "\r\n--$boundary\r\nContent-Disposition: form-data; name=\"sel\"\r\n\r\n1\r\n--$boundary\r\nContent-Disposition: form-data; name=\"txt\"\r\n\r\n322133text\r\n--$boundary\r\nContent-Disposition: form-data; name=\"Upload\"\r\n\r\nUpload\r\n--$boundary".'--'; $Instance->{length} = length $content; $Instance->{contentReady} = $hdrs_as_string.$Instance->{length}."\r\n".$content."\r\n\r\n"; print $Instance->{contentReady}; return $Instance;
( there must be file upload too, but I leave it away for easiest debugging ). When I use a web browser, It's all right - data passed well. But when I use my perl script (just sending prepared data to opened socket), I get php warnings "Undefined index ..." and empty $_REQUEST (but no any http or php errors more). What can be wrong?...Code:<?php if($_REQUEST['upload']) { echo $_REQUEST['upload']; } if($_REQUEST['txt']) { echo $_REQUEST['txt']; } if($_REQUEST['sel']) { echo $_REQUEST['sel']; } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data"> <select name="sel"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <input type="text" name="txt"><br> <input type="submit" value="Upload" name="upload"> </form>


Reply With Quote