Fray Fray -3 years ago 182
HTTP Question

PHP - Extract data from Http Post (Angular)

I have this function (angular) to send information to php page:

public SendData(cart_items:any) {
const jsonContent = new RequestOptions({
headers:new Headers({
'Content-Type': 'application/json'
let body = JSON.stringify(cart_items);
return"xxxxxxxxxx/pay.php", body, jsonContent)
.map(result => {
return result.json();

how can i get access to data in the page 'pay.php'

Answer Source

This is more of a pure php question, but you do this:

 $json = file_get_contents('php://input');
    $obj = json_decode($json, true);
    $name = $obj['name'];
    $age = $obj['age'];

This would work if the object you're posting is like this: { "name":"My Name", "age":"24" }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download