vaibhav jain
vaibhav jain

Reputation: 361

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

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;
});

Upvotes: 1

Views: 239

Answers (1)

vstelmakh
vstelmakh

Reputation: 772

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.

Upvotes: 1

Related Questions