Slim request header is setting text/html, even i am using withJson.

牧云@^-^@ 提交于 2019-12-11 04:44:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!