ID: 47684
Updated by: [email protected]
Reported By: r-ser at yandex dot ru
-Status: Open
+Status: Feedback
Bug Type: HTTP related
Operating System: Linux 2.6.26
PHP Version: 5.2.9
New Comment:
Why are you not passing the content-length in there..? I mean, isn't
that the obvious error..? :)
Previous Comments:
------------------------------------------------------------------------
[2009-03-17 00:15:55] r-ser at yandex dot ru
Description:
------------
When use file_get_contents + stream_context_create to post file to web
server and the page in web server return redirect to another page
("location" field in answer), then file_get_contents requested
redirected page with POST header without "Content-Length:" field in
request and server response "HTTP/1.0 411 Length Required".
I think, it's two ways to fix problem
1) 'method' must be change to GET in requests to redirect pages.
2) Add 'Content-Length: 0' to next POST redirect requests
Reproduce code:
---------------
$argv[1] = "image.jpg";
$boundary = "AaB03x1234567890";
$type = mime_content_type($argv[1]);
$data = "--$boundary\r\nContent-Disposition: form-data;
name=\"fileupload\"; filename=\"".basename($argv[1])."\"
Content-Type: ".$type." \r\nContent-Transfer-Encoding:
binary\r\n\r\n".file_get_contents($argv[1])."\r\n--$boundary--";
$header = "Content-type: multipart/form-data, boundary=$boundary";
$context = stream_context_create(array('http' =>
array('method'=>'POST', 'header'=> $header, 'content' => $data)));
$result = file_get_contents('http://load.imageshack.us', false,
$context);
echo $result;
Expected result:
----------------
failed to open stream: HTTP request failed! HTTP/1.0 411 Length
Required
Actual result:
--------------
Normal redirected page
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47684&edit=1