Home > Backend Development > Python Tutorial > Python和php通信乱码问题解决方法

Python和php通信乱码问题解决方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:44:34
Original
1221 people have browsed it

即使在urlencode之前str.decode(“cp936″).encode(“utf-8″)做了编码转换也是没用的。后来查询手册查到一个urllib.quote()函数,用此方法成功解决!
python端:

复制代码 代码如下:

str = "中文"
str = urllib.quote(str.decode("cp936").encode("utf-8"))
postData = {}
postData['str'] = str
...post请求发送代码...

php端:
复制代码 代码如下:

$str = urldecode($_POST['str'])
echo $str;

完美解决乱码问题!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template