|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-06-09 03:36 UTC] mike@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
Description: ------------ Reading the PHP input stream with the fopen('php://input') routine before calling http_get_request_body() on a PUT HTTP request. Here are some examples: A POST request: ********************************************************* PUT http://example.com/requestbodytest.php HTTP/1.1 Host: example.com Keep-Alive: 300 Connection: keep-alive Content-Type: text/xml Content-Length: 58 <?xml version="1.0" encoding="utf-8" ?> <body>test</body> ********************************************************* with the following script: ********************************************************* <?php $body = ''; $fh = @fopen('php://input', 'r'); if ($fh) { while (!feof($fh)) { $s = fread($fh, 1024); if (is_string($s)) { $body .= $s; } } fclose($fh); } print("-------------- PHP Input Stream ----------------\n$body\n\n"); $body2 = http_get_request_body(); print("---------- http_get_request_body() -------------\n$body2\n\n"); ?> ********************************************************* outputs this: ********************************************************* -------------- PHP Input Stream ---------------- <?xml version="1.0" encoding="utf-8" ?> <body>test</body> ---------- http_get_request_body() ------------- <?xml version="1.0" encoding="utf-8" ?> <body>test</body> ********************************************************* The same request to the same script using an HTTP PUT request, however, outputs this: ********************************************************* -------------- PHP Input Stream ---------------- <?xml version="1.0" encoding="utf-8" ?> <body>test</body> ---------- http_get_request_body() ------------- *********************************************************