我正在为我的移动应用编写第一个api。该应用程序正在启动对服务器的http调用,我可以看到呼叫消失,我的应用程序正在从服务器记录HTTP 200 OK响应。但是,即使使用最基本的测试代码,我也没有看到任何从服务器返回的内容:
<?php
// Helper method to get a string description for an HTTP status code
function getStatusCodeMessage($status) {
$codes = Array(
... some basic codes edited down
200 => 'OK',
301 => 'Moved Permanently',
302 => 'Found',
400 => 'Bad Request',
... // more edited out
);
return (isset($codes[$status])) ? $codes[$status] : '';
}
// Helper method to send a HTTP response code/message
function sendResponse($status, $body, $content_type = 'text/html') {
$status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
header($status_header);
header('Content-type: ' . $content_type);
echo $body;
}
var $testB = json_encode(array(
"testB" => "has worked",
"apiDataB" => "accepted"
)) ;
sendResponse(200, json_encode($testB));
// I then changed this to 400 just to see if the app recorded the 400 response
// but it did not, it still recorded `200 OK`
?>
我希望看到一个JSON Object $ testB回到应用程序但是应用程序正在录制:
HTTP/1.1 200 OK
Date: Tue, 25 Oct 2016 21:23:44 GMT
Server: Apache/2.4.23
X-Powered-By: PHP/5.4.45
Vary: User-Agent
Content-Length: 0
Keep-Alive: timeout=5
Connection: Keep-Alive
Content-Type: text/html
预览/响应组件(来自Chrome Inspector)是空白的。我在这里缺少什么?