Moa*_*oak 4 php gzip http-post laravel-5 lumen
我收到来自第三方的 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(),
];
}
);
Run Code Online (Sandbox Code Playgroud)
我的测试文件test.txt
hello world!
Run Code Online (Sandbox Code Playgroud)
我的健全性检查:
curl --data-binary @test.txt -H "Content-Type: text/plain" -X POST http://localhost:8000/testgzip
{"body":"hello world!"}
Run Code Online (Sandbox Code Playgroud)
为了压缩它,我运行命令
gzip test.txt
我的卷发:
curl --data-binary @test.txt.gz -H "Content-Type: text/plain" -H "Content-Encoding: gzip" -X POST http://localhost:8000/testgzip
Run Code Online (Sandbox Code Playgroud)
这会触发一个
我还尝试了 gzuncompress 触发
我究竟做错了什么?如何解压缩 gzip 请求?
对于 gzip 压缩的内容,您需要使用gzdecode().
$decompressed = gzdecode($request->getContent());
Run Code Online (Sandbox Code Playgroud)
这是 PHP 内置的。
gzinflate() 处理压缩(未 gzip 压缩)字符串,gzuncompress() 处理压缩(未 gzip 压缩)字符串。
文件:
| 归档时间: |
|
| 查看次数: |
5217 次 |
| 最近记录: |