我在urllib2 json类型的帮助下调用了很多api。但是现在我想在urllib2的帮助下创建数据源api,它不起作用
我有发布api和url以及此数据
Dummy url = https://www.example.com/xyz?id=32323232
dummy data {'data': "here"}
数据应通过表单数据而非原始json类型发送
我们如何使用urllib2在python中编写代码
您可以使用urllib发送数据和标题,如下所示。
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
url = https://www.example.com/xyz?id=32323232
data = {'data': "here"}
header = {'ContentType' : 'multipart/form-data'}
request = urllib2.Request(url, data, header)
response = urllib2.urlopen(request)
参考:https://www.pythonforbeginners.com/python-on-the-web/how-to-use-urllib2-in-python/