我知道已经有人问过这个问题:Compress string in php and decompress in python
但没有提供答案(聊天中的讨论已丢失)
我希望PHP客户端压缩一个字符串,将其作为包含在json中的字符串发送到服务器,然后我希望能够对其进行解压缩
我试过zlib:
$ php -a
Interactive shell
php > $msg = "abcdefghijk";
php > $compressed = gzcompress($msg);
php > echo "'".$compressed."'"
php > ;
'x�KLJNIMK�����c'
$ python3
Python 3.7.8 (heads/master-dirty:daa285d, Jul 28 2020, 20:00:50)
[GCC 9.3.1 20200408 (Red Hat 9.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
>>> comp_msg=r'x�KLJNIMK�����c'
>>> msg = zlib.decompress(comp_msg.encode('utf-8'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
zlib.error: Error -3 while decompressing data: incorrect header check
。。。但它不起作用。 我猜这是字符串编码的问题,但是使用PHP的mb_convert_编码($compressed,“UTF-8”);这并不能解决问题
我不能问这个问题第一次出现的创造者,因为缺乏声誉。。。 任何帮助都将不胜感激
谢谢
b
前缀:相关问题 更多 >
编程相关推荐