Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | $data = array( |
---|
4 | "method" => strtoupper($_SERVER["REQUEST_METHOD"]), |
---|
5 | "headers" => array(), |
---|
6 | "content" => null |
---|
7 | ); |
---|
8 | |
---|
9 | foreach($_SERVER as $key => $value){ |
---|
10 | if(strpos($key, "HTTP_") === 0){ |
---|
11 | $data["headers"][strtr(strtolower(substr($key, 5)), "_", "-")] = $value; |
---|
12 | } |
---|
13 | } |
---|
14 | |
---|
15 | if($data["method"] === "GET"){ |
---|
16 | $data["content"] = $_GET; |
---|
17 | }elseif($data["method"] === "PUT" || $data["method"] === "POST"){ |
---|
18 | $data["content"] = json_decode(file_get_contents("php://input"), true); |
---|
19 | } |
---|
20 | |
---|
21 | header("Content-Type: application/json"); |
---|
22 | header("Cache-Control: no-cache"); |
---|
23 | echo json_encode($data); |
---|
Note: See
TracBrowser
for help on using the repository browser.