如何用Python写一个http post请求
1个回答
展开全部
import httplib, urllib
from urlparse import urlparse
def httppost(url, **kwgs):
httpClient = None
conn = urlparse(url)
try:
params = urllib.urlencode(dict(kwgs))
header = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain", }
httpClient = httplib.HTTPConnection(conn.netloc, conn.port, timeout=30)
httpClient.request("POST", conn.path, params, header)
response = httpClient.getresponse()
print response.status
print response.reason
print response.read()
print response.getheaders()
except Exception, e:
print e
finally:
if httpClient:
httpClient.close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询