在Python2中,urllib2
和urllib
中的方法组合就可以做到这一点.下面是我如何使用这两个工具发布数据:
post_data = [('name','Gladys'),] # a sequence of two element tuples
result = urllib2.urlopen('http://example.com', urllib.urlencode(post_data))
content = result.read()
urlopen()是用于打开URL的方法. urlencode()将参数转换为百分比编码字符串.