使用dictionary定义参数,发送请求时requests模块会自动url编码处理参数.但有些时候可能不需要编码,要求参数原样输出,这个时候将参数直接定义成字符串即可.
import requests
proxy = {"http":"http://127.0.0.1:8080",
"https":"http://127.0.0.1:8080"}
def retest():
url = "http://www.baidu.com"
pstr1 = "name=中文".encode("utf-8")
requests.post(url = url,data = pstr1, proxies = proxy)
注:参数需要utf-8编码,否则会报错use body.encode(‘utf-8’) if you want to send it encoded in utf-8.
最后效果如下图,参数原样输出:
对python中使用requests模块参数编码的不同处理方法