【发布时间】:2019-08-18 02:29:45
【问题描述】:
我收到来自第三方的请求,这些请求是 gzip 编码的文本(~1mb 所以有意义)
我的测试路线:
$router->post(
'testgzip',
function (\Illuminate\Http\Request $request) {
$decompressed = null;
if ($request->header('content-encoding') === 'gzip') {
$decompressed = gzinflate($request->getContent());
}
return [
'body' => $decompressed ?? $request->getContent(),
];
}
);
我的测试文件test.txt
hello world!
我的健全性检查:
curl --data-binary @test.txt -H "Content-Type: text/plain" -X POST http://localhost:8000/testgzip
{"body":"hello world!"}
要压缩它,我运行命令
gzip test.txt
我的卷发:
curl --data-binary @test.txt.gz -H "Content-Type: text/plain" -H "Content-Encoding: gzip" -X POST http://localhost:8000/testgzip
触发一个
gzinflate(): 数据错误
我也试过 gzuncompress 触发
gzuncompress(): 数据错误
我做错了什么?如何解压 gzip 请求?
【问题讨论】:
标签: php laravel-5 http-post gzip lumen