python 发送http请求填坑
来源:互联网 发布:天蝎网络第二季看不到 编辑:程序博客网 时间:2024/06/14 21:04
先说问题:最近开始使用python的urllib2和urllib来请求webservice获取数据,但是服务器是java的服务器,发现python传入的参数(中文)在服务器端显示的是乱码,在网上搜索了一整天,终于整出来了,特此填坑。
1.环境:python2.7.10,rhel5.5
2.代码:
import urllib2import urlliburl = "https://www.baidu.com"para1 = {'haha',"哈哈"}#因为有中文,所以用 urllib.quote()para1 = urllib.quote(para1)para = urllib.urlencode(para1)f = urllib2.urlopen(url,data=para)buf = f.read()f.close()
主要函数功能说明:
urllib.quote(string[, safe]):对字符串进行编码。参数 safe 指定了不需要编码的字符。urllib.unquote(string) :对字符串进行解码。
urllib.urlencode(query[, doseq]):将dict或者包含两个元素的元组列表转换成url参数。
注意:java服务器端需要修改部分代码,需要将请求参数进行utf-8解码。
阅读全文
0 0
- python 发送http请求填坑
- python发送HTTP请求
- python发送HTTP请求
- python发送HTTP请求
- python发送http请求
- python 发送http请求
- python发送HTTP请求
- python发送HTTP GET请求
- python发送HTTP GET请求
- Python发送HTTP GET请求
- 鉴客 python发送HTTP请求
- python 发送http post请求
- Python之使用Python发送HTTP请求
- Python发送HTTP请求工具包httplib
- Python发送HTTP请求工具包httplib
- 使用python发送http请求代码
- python发送http请求之requests模块
- python使用urllib2发送http请求
- Java与算法(1)
- Hive开发经验总结
- MariaDB数据库安装完需要初始化操作
- sizeof与strlen
- 使用JDBCTemplate实现与Spring结合,方法公用 ——Spring配置(applicationContext.xml)
- python 发送http请求填坑
- USB协通讯议(很好的一篇文章)
- Openstack Neutron扩展实现细节(QOS)
- 又遇到vmware不能启动了(vmware12/Deepin15.4(4.9.0kernel))
- 一次一密文件加密程序
- 【12.1】c++ primer plus 课后编程答案
- 找出Vector中所有最小值
- JS创建对象的几种方式
- CNN