是否可以将这段代码改编为 make put 请求:
#!/usr/bin/python
import urllib2, base64, urllib
dir="https://domain.com/api/v1/"
use="one@two.com"
pas="123456"
base64string = base64.encodestring('%s:%s' % (use, pas)).replace('\n', '')
request = urllib2.Request(dir, headers={"Authorization" : "Basic %s" % base64string})
response = urllib2.urlopen(request).read()
print response
我尝试使用其他代码,但我认为它会执行获取请求,不是吗?
#!/usr/bin/python
import urllib2, base64, urllib
dir="https://domain.com/api/v1/"
use="one@two.com"
pas="123456"
values = {
'list' :["201.22.44.12","8.7.6.0/24"]
}
data = urllib.urlencode(values)
base64string = base64.encodestring('%s:%s' % (use, pas)).replace('\n', '')
request = urllib2.Request(dir, data, headers={"Authorization" : "Basic %s" % base64string})
response = urllib2.urlopen(request).read()