aherlambang
aherlambang

Reputation: 14418

parse POST request from HTTP Request body

What is the best and easiest way to get the HTTP Body from the POST request and parse it with variables? Say I have two attributes called latitude and longitude in the body in which the values I want to extract.

Another thing is how can I test it so I can see these values?

Upvotes: 1

Views: 10450

Answers (3)

Andrew Cooper
Andrew Cooper

Reputation: 32576

In your PHP which handles the POST request you can do something like:

$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];

Some browsers have developer tools that allow you to see the POST data that the browser sent. I use the FireBug plug-in for Firefox. I think the built-in developer tools in IE 8 and above (F12 I think) can do the same thing. Not sure about Chrome, but I'm sure there's something around.

Upvotes: 2

Myles
Myles

Reputation: 21500

You're a little unclear in your question, if what you're asking is how to get the values of post variables, then PHP has the $_POST super global that you can reference as $_POST['key'].

If what you're asking is how to get some xml or something from the post body and parse it for values you might try the $HTTP_RAW_POST_DATA super global. It would depend how the data is formatted when it gets there.

Upvotes: 2

bensiu
bensiu

Reputation: 25564

read to $_POST like this:

echo '<pre>';
  print_r ( $_POST );
echo '</pre>'

and to access: $_POST [variablename] read more at: https://www.php.net/manual/en/reserved.variables.post.php

Upvotes: 1

Related Questions