0
5385
POST
from urllib.parse import urlencode
from urllib.request import Request, urlopen
url = 'https://httpbin.org/post' # Set destination URL here
post_fields = {'foo': 'bar'} # Set POST fields here
request = Request(url, urlencode(post_fields).encode())
request.get_method = lambda: 'POST'
json = urlopen(request).read().decode()
print(json)
{
"args": {},
"data": "",
"files": {},
"form": {
"foo": "bar"
},
"headers": {
"Accept-Encoding": "identity",
"Connection": "close",
"Content-Length": "7",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Python-urllib/3.6"
},
"json": null,
"origin": "122.167.155.116",
"url": "https://httpbin.org/post"
}
PUT
from urllib.parse import urlencode
from urllib.request import Request, urlopen
url = 'https://httpbin.org/put' # Set destination URL here
post_field_data = {'foo': 'bar'} # Set PUT fields here
request = Request(url, urlencode(post_field_data).encode())
request.get_method = lambda: 'PUT'
json = urlopen(request).read().decode()
print(json)
{
"args": {},
"data": "",
"files": {},
"form": {
"foo": "bar"
},
"headers": {
"Accept-Encoding": "identity",
"Connection": "close",
"Content-Length": "7",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Python-urllib/3.6"
},
"json": null,
"origin": "122.167.155.116",
"url": "https://httpbin.org/put"
}
Comment here