您的客户端的行为符合其应有的行为,例如,nc -l 8888
作为服务器运行并发出请求:
import requests
requests.post('http://localhost:8888', data={u'post': u'Andr\xe9 T\xe9chin\xe9'})
显示:
POST / HTTP/1.1
Host: localhost:8888
Content-Length: 33
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate, compress
Accept: */*
User-Agent: python-requests/1.2.3 cpython/2.7.3
post=Andr%C3%A9+T%C3%A9chin%C3%A9
您可以检查是否正确:
>>> import urllib
>>> urllib.unquote_plus(b"Andr%C3%A9+T%C3%A9chin%C3%A9").decode('utf-8')
u'Andr\xe9 T\xe9chin\xe9'
headers = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}
正文仅包含ascii字符,因此不会受到伤害,并且正确的服务器x-www-form- urlencoded
无论如何都会忽略类型的任何参数。在URL编码的表单数据中查找血腥细节