admin管理员组文章数量:1134573
I'm using PHP, ExtJS and ajax store.
It sends data (on create, update, destroy) not in POST or GET. In the Chrome Console I see my outgoing params as JSON in the "Request Payload"
field. $_POST
and $_GET
are empty.
How to retrieve it in PHP?
I'm using PHP, ExtJS and ajax store.
It sends data (on create, update, destroy) not in POST or GET. In the Chrome Console I see my outgoing params as JSON in the "Request Payload"
field. $_POST
and $_GET
are empty.
How to retrieve it in PHP?
Share Improve this question edited May 15, 2023 at 3:52 ggorlen 56.6k8 gold badges109 silver badges149 bronze badges asked Mar 7, 2012 at 6:56 nkuhtankuhta 11.1k12 gold badges44 silver badges55 bronze badges2 Answers
Reset to default 289If I understand the situation correctly, you are just passing json data through the http body, instead of application/x-www-form-urlencoded
data.
You can fetch this data with this snippet:
$request_body = file_get_contents('php://input');
If you are passing json, then you can do:
$data = json_decode($request_body);
$data
then contains the json data is php array.
php://input
is a so called wrapper.
php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".
Also you can setup extJs writer
with encode
: true
and it will send data regularly (and, hence, you will be able to retrieve data via $_POST
and $_GET
).
... the values will be sent as part of the request parameters as opposed to a raw post (via docs for encode config of Ext.data.writer.Json)
UPDATE
Also docs say that:
The encode option should only be set to true when a root is defined
So, probably, writer
's root
config is required.
本文标签: phpHow to retrieve Request PayloadStack Overflow
版权声明:本文标题:php - How to retrieve Request Payload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736842632a1955167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论