0

This is my code

<?php

$method = $_SERVER['REQUEST_METHOD'];

switch ($method) {
  case 'POST':
    rest_post();  
    break;
  case 'GET':
    rest_get();  
    break;
  default:
    rest_error();  
    break;
}

function rest_get(){
    $url = $_SERVER['QUERY_STRING'];
    parse_str($url, $get_array);
    print_r($get_array);
}

function rest_post(){
    // display post params as array
}

HTTP GET

/index.php?q=hi&q2=hello

Output:

Array
(
    [q] => hi
    [q2] => hello
)

I just like to do the same to HTTP POST but I don't have any idea how to it. For example I don't know what type of post data I will be getting.

Adrian Enriquez
  • 8,175
  • 7
  • 45
  • 64

1 Answers1

1

Solved it already. Thanks

function rest_post(){
    $postdata = file_get_contents("php://input");
    parse_str($postdata, $get_array);
    print_r($get_array);
}
Adrian Enriquez
  • 8,175
  • 7
  • 45
  • 64