python3.4中的post请求怎么写
展开全部
from urllib import request
request.urlopen()
def post(url, data=None, headers=None, timeout=2, decode='utf-8'):
rt = HttpReturn()
if headers is None:
headers = {}
post_data = urllib.parse.urlencode(data).encode(decode)
try:
req = urllib.request.Request(url, post_data, headers)
hr = urllib.request.urlopen(req, timeout=timeout)
rt = HttpReturn()
rt.obj = rt
rt.text = hr.read().decode('utf-8')
rt.status = hr.status
finally:
return rt
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询