Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Get body of request received

I am currently working with a 3rd party API which I cannot disclose. The summary is:

action -> 3rd party -> callback

So my server communicates with 3rd party with some data

Once the data is sent back, the 3rd party sends an XML to the callback url.

I am receiving the callback with the headers:

Content-type: application/xml Content-length: 69 Request-method: POST

However, print_r($_POST) is showing nothing at all. Nor is $_GET.

What could be going on? I know you cannot give me the most detailed answer based on my vagueness but if you could point me in the right direction, that would be brilliant.

like image 262
Ozzy Avatar asked Dec 05 '12 16:12

Ozzy


People also ask

Can we use @requestbody with GET?

Yes, you can send a request body with GET but it should not have any meaning.

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 does $Request do in PHP?

PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag.

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() .


1 Answers

Use php://input :

$post = file_get_contents('php://input');
like image 118
John Conde Avatar answered Oct 11 '22 18:10

John Conde