以下是我正在使用的代码。
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
function handle_response($output, $response){
if($output['status'] === "failed"){
$response = $response->withStatus(400);
$response->getBody()->write(json_encode($output));
}
else{
$response->getBody()->write(json_encode($output));
}
return $response;
}
/* user profile */
$app->get('/user/profile', function (Request $request, Response $response) {
$headers = $request->getHeaders();
foreach ($headers as $name => $values) {
$name . ": " . implode(", ", $values);
}
if ($request->hasHeader('Authorization')) {
$output['token'] = 'yes';
}
else
$output['token'] = $name;
$output['status'] = "success";
return handle_response($output, $response);
});
我在谷歌浏览器中使用邮递员来测试这个 REST 服务。我将自定义标头“授权”与 GET 请求一起传递。但是,该程序无法识别任何自定义标头。
代码块
$headers = $request->getHeaders();
foreach ($headers as $name => $values) {
$name . ": " . implode(", ", $values);
}
仅返回标头“HTTP_ACCEPT_LANGUAGE”。
请帮我弄清楚,这里出了什么问题。