Bug #64891 [Opn->Nab]: POST values in Google Chrome XHR.
| From: | googleguy@php.net | Date: | Tue, 21 May 2013 22:15:42 +0000 |
| Subject: | Bug #64891 [Opn->Nab]: POST values in Google Chrome XHR. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179054@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64891&edit=1
ID: 64891
Updated by: googleguy@php.net
Reported by: marc at kryn dot org
Summary: POST values in Google Chrome XHR.
-Status: Open
+Status: Not a bug
Type: Bug
Package: Built-in web server
Operating System: OS X 10.8.2
PHP Version: 5.4.15
Block user comment: N
Private report: N
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
This doesn't appear to be a bug in PHP. It looks to me like FireFox and some
other UAs will modify the request headers resulting from that javascript code to
comply with the spec.
Chrome seems to be sending a request, as a result of that javascript XHR, that
is missing both the charset in the Content-type header as well as a Content-
length header. If I just let the UA do the encoding and formulate the request
properly through javascript I get the expected result:
<?php
if (isset($_GET['test'])) {
echo 'received values: <br/>';
var_dump(file_get_contents("php://input"),$_POST,$_GET);
exit;
}
?>
<div id="response"></div>
<form id="myform">
<input name="foo" value="bar" type="text" />
</form>
<script>
var xhr = new XMLHttpRequest();
xhr.open('POST', '<?= $_SERVER['SCRIPT_NAME'] ?>?test=1', true);
xhr.onload = function(){ document.getElementById('response').innerHTML =
this.responseText; };
var frm = new FormData(document.getElementById("myform"));
xhr.send(frm);
</script>
This works for me in all the latest versions of Chrome, FireFox, Opera, Safari,
and IE.
Please feel free to reopen this bug report if you have additional evidence of a
bug in PHP.
Previous Comments:
------------------------------------------------------------------------
[2013-05-21 21:24:06] marc at kryn dot org
Description:
------------
The PHP file servered through the built-int web server does not receive somehow
the POST values from a AJAX/XHR POST call in Google Chrome. Only in Google Chrome.
Setup:
- Create the file from the test script.
- Open a built-in web server
php54 -S 127.0.0.1:8000 -t web/
- Open the file http://127.0.0.1:8000/test.php`
This behaviour happens only for the built-in web server and Google Chrome. It
works fine when running PHP behind fpm or as apache module. Any other browser
works in all combinations (built-in server or not).
Tested on 5.4.15-1 installed through mac ports.
Test script:
---------------
<?php
if (isset($_GET['test'])) {
echo 'received values: <br/>';
var_dump($_POST);
exit;
}
?>
<div id="response"></div>
<script>
var xhr = new XMLHttpRequest();
xhr.open('POST', '<?= $_SERVER['SCRIPT_NAME'] ?>?test=1', true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onload = function(){ document.getElementById('response').innerHTML =
this.responseText; };
xhr.send('foo=bar');
</script>
Expected result:
----------------
received values:
array (size=1)
'foo' => string 'bar' (length=3)
Actual result:
--------------
received values:
array (size=0)
empty
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64891&edit=1