Edit report at http://bugs.php.net/bug.php?id=54137&edit=1

 ID:                 54137
 Comment by:         christophe dot bliard at trux dot info
 Reported by:        maurice-php at mertinkat dot net
 Summary:            file_get_contents POST request sends additional line
                     breaks
 Status:             Open
 Type:               Bug
 Package:            Streams related
 Operating System:   all
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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

Reply via email to