Logo

Programming-Idioms

History of Idiom 174 > diff from v8 to v9

Edit summary for version 9 by random:
New Python implementation by user [random]

Version 8

2019-07-15, 16:32:27

Version 9

2019-09-26, 13:28:18

Idiom #174 Make HTTP POST request

Make a HTTP request with method POST to URL u

Idiom #174 Make HTTP POST request

Make a HTTP request with method POST to URL u

Imports
from urllib import request, parse
Code
data = parse.urlencode(<your data dict>).encode()
req =  request.Request(u, data=data, method="POST")
resp = request.urlopen(req)
Comments bubble
Explicit use of the "method" parameter, because "GET" is used when "data" is None
Doc URL
https://docs.python.org/3/library/urllib.request.html#urllib.request.Request
Origin
https://stackoverflow.com/questions/36484184/python-make-a-post-request-using-python-3-urllib