问题
I am using slim withJson method to return header application json. But its returning text/html header. When i echo header of response object, it is application/json. So why it is returning text/html header in rest client or browser.
$app->get('/login', function($request,$response){
$data = [['name'=>'vaibhav']];
$newResponse = $response->withJson($data);
echo $newResponse->getHeaderLine('Content-Type');
return $newResponse;
});
回答1:
I think this is because you are doing echo $newResponse->getHeaderLine('Content-Type');
and then slim tries to send headers.
Try to comment echo string and check.
来源:https://stackoverflow.com/questions/45139245/slim-request-header-is-setting-text-html-even-i-am-using-withjson