如何用Python写一个http post请求
答案:1 悬赏:60 手机版
解决时间 2021-02-16 05:41
- 提问者网友:且恨且铭记
- 2021-02-15 18:52
如何用Python写一个http post请求
最佳答案
- 五星知识达人网友:迷人又混蛋
- 2021-02-15 19:55
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()
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()
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯