我有一个程序,它在 curl 请求的回复中搜索特定字符串。我有时会得到压缩数据。有没有办法找到回复是文本格式还是压缩格式? header 有时包含 gziipped、deflate header ,但它不一致。有没有办法搜索字符串并查看其是否已压缩?
最佳答案
您可以尝试查看数据的前两个字节。对于压缩数据,they should be 0x1f, 0x8b .
Member header and trailer
ID1 (IDentification 1)
ID2 (IDentification 2)
These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 (0x8b, \213),
to identify the file as being in gzip format.
关于c++ - 查找正文是否包含压缩数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5631710/