Bug #54137 [NEW]: file_get_contents POST request sends additional line breaks

From: Date: Wed, 02 Mar 2011 13:45:03 +0000
Subject: Bug #54137 [NEW]: file_get_contents POST request sends additional line breaks
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-159155@lists.php.net to get a copy of this message
From:             
Operating system: all
PHP version:      5.3.5
Package:          Streams related
Bug Type:         Bug
Bug description:file_get_contents POST request sends additional line breaks

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 bug report at http://bugs.php.net/bug.php?id=54137&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=54137&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=54137&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=54137&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=54137&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54137&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=54137&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=54137&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=54137&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=54137&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=54137&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=54137&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=54137&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=54137&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=54137&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54137&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54137&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=54137&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=54137&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=54137&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=54137&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=54137&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#159155) next »