您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python请求编码POST数据

Python请求编码POST数据

您的客户端的行为符合其应有的行为,例如,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编码的表单数据中查找血腥细节

python 2022/1/1 18:47:57 有343人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶