我需要一个关于POST如何使用Python的示例。
这样的事情,但是有效。
import httplib, urllib
conn = httplib.HTTPConnection("www.google-analytics.com")
conn.request("POST", "v=1&tid=UA-XXXXXX-Y&cid=666&t=event&ec=game&ea=start&ev=0")
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
答案 0 :(得分:7)
您只需要一个网址:
conn.request("POST", "/collect", "v=1&tid=UA-XXXXXX-Y&cid=666&t=event&ec=game&ea=start&ev=0")
或者使用字典:
import httplib, urllib
params = urllib.urlencode({
'v': 1,
'tid': 'UA-XXXXXX-Y',
'cid': '666',
't': 'event',
'ec': 'game',
'ea': 'start',
'ev': 0
})
connection = httplib.HTTPConnection('www.google-analytics.com')
connection.request('POST', '/collect', params)