Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve Request Payload

People also ask

How do you find payload data?

You can use explode() on "&" then you will get data in array format. so if your payload string is not at fixed position then you can use foreach loo p in which you can find the payload string is present in string or not with help of strchr() .

How can I get payload data in PHP?

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);

What is the payload of a request?

A request payload is data that clients send to the server in the body of an HTTP POST, PUT, or PATCH message that contains important information about the request.

Is request payload same as request body?

So Yes, they are the same thing. Show activity on this post. So basically the only difference between HTTP message body and HTTP message payload body is encoding (but only if present). So generalizing the term request payload = request body.


If 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.