返回“文本/纯”与苗条3

问题描述:

我正在写一个路线,应该返回一个“文本/纯”内容类型(只为这条路线)。返回“文本/纯”与苗条3

$response->withHeader('Content-type', 'text/plain')->write("HELLO");

上午我做错了?我一直在获取“text/html”。

+0

请出示整条线路。 – jmattheis

我假设您不返回或重新分配withHeader-方法返回的Response,因为默认内容类型为text/plain

Response -object是不可变的,因此只返回withX-方法中更改的对象。

解决的办法是返回响应

$app->get('/foo', function($request, $response) { 
    return $response->withHeader('Content-Type', 'text/plain')->write('HELLO'); 
});