2.0.10 header好像无法设置,求助。
版本是2.1.0,打错了。
return download($filePath, '1.xlsx', true);
用这样的代码可以。
恭喜~
同问
部署到nginx转发api会出现重复头 2024/07/30 08:27:20 [error] 13272#15132: *18 upstream sent duplicate header line: "Content-Length: 8474", previous value: "Content-Length: 8474" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /ls/api/admin/Statement/download/id/19.xlsx?batoken=4a4f7907-ce10-45c3-82ce-8d2cf3d35ced&server=1 HTTP/1.1", upstream: "http://127.0.0.1:8000/admin/Statement/download/id/19.xlsx?batoken=4a4f7907-ce10-45c3-82ce-8d2cf3d35ced&server=1", host: "localhost"
// 避免输出到命令行窗口 while (ob_get_level() > 1) { ob_end_clean(); } ob_start(); $http = $app->http; $response = $http->run(); $content = ob_get_clean(); ob_start(); $response->send(); $app->http->end($response); $content .= ob_get_clean() ?: ''; $connection->send(new Response($response->getCode(), $response->getHeader(), $content)); 这里对于文件输出可能重复头了。
$responseClass = get_class($response); $headers = $response->getHeader(); if (isset($headers['Content-Length'])) { unset($headers['Content-Length']); } if ($responseClass !== 'think\response\File') { $connection->send(new Response($response->getCode(), $response->getHeader(), $content)); } else { $connection->send(new Response($response->getCode(), $headers, $content)); }
版本是2.1.0,打错了。
return download($filePath, '1.xlsx', true);
用这样的代码可以。
恭喜~
同问
部署到nginx转发api会出现重复头
2024/07/30 08:27:20 [error] 13272#15132: *18 upstream sent duplicate header line: "Content-Length: 8474", previous value: "Content-Length: 8474" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /ls/api/admin/Statement/download/id/19.xlsx?batoken=4a4f7907-ce10-45c3-82ce-8d2cf3d35ced&server=1 HTTP/1.1", upstream: "http://127.0.0.1:8000/admin/Statement/download/id/19.xlsx?batoken=4a4f7907-ce10-45c3-82ce-8d2cf3d35ced&server=1", host: "localhost"
- 1
前往