Edit report at http://bugs.php.net/bug.php?id=54137&edit=1
ID: 54137 Updated by: [email protected] Reported by: maurice-php at mertinkat dot net Summary: file_get_contents POST request sends additional line breaks -Status: Open +Status: Closed Type: Bug Package: Streams related Operating System: all PHP Version: 5.3.5 -Assigned To: +Assigned To: iliaa Block user comment: N Private report: N New Comment: This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2011-05-29 11:23:10] [email protected] Automatic comment from SVN on behalf of iliaa Revision: http://svn.php.net/viewvc/?view=revision&revision=311542 Log: Fixed bug #54137 (file_get_contents POST request sends additional line break). ------------------------------------------------------------------------ [2011-05-17 01:08:14] spam at abma dot de is this the same bug https://bugs.launchpad.net/ubuntu/+source/php5/+bug/650779 ? ------------------------------------------------------------------------ [2011-04-26 09:12:02] xiezhenye at gmail dot com I also meet with this problem. As http protocol, message body size should exactly match the content-length. when there exists unwanted "\r\n\r\n", it maybe cause some unexpected result, as connect resetted by server. ------------------------------------------------------------------------ [2011-03-14 18:25:35] christophe dot bliard at trux dot info I have the same problem here, with PHP 5.3.2 and also 5.2.10. Another thing that may be interesting: if you do the same HTTP POST request on a web server on localhost, then there will not be any "\r\n\r\n" after the request. ------------------------------------------------------------------------ [2011-03-02 14:45:02] maurice-php at mertinkat dot net Description: ------------ When doing HTTP POST requests using file_get_contents and an appropriate stream context (http method = POST, content = ...) two additional line breaks ("\r\n\r\n") are added below the POST message body. This is wrong according to the default encoding "application/x-www-form-urlencoded" and has been seen to upset some webservers (content length is incorrect). Run the testscript and check the traffic using tcpdump/tcpflow or wireshark. You'll see additional lines at the end of the message body. Attached is a very simple patch against http_fopen_wrapper.c from PHP 5.3.5 source which removes sending "\r\n\r\n". Test script: --------------- <?php $ctx = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => 'a=1&b=2', ) )); $response = file_get_contents('http://www.php.net/', false, $ctx); echo $response; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54137&edit=1
