Tools, FAQ, Tutorials:
HTTP POST with urllib.request
How to send an HTTP POST request with urllib.request? I want to submit a form to a Website.
✍: FYIcenter.com
To submit a form to a Website, you can use the
urllib.request.urlopen() function with two arguments:
r = urllib.request.urlopen(url, data) where: url can be a URL string or Request object data is request body as a binary string.
Here is a Python example on how to send a POST request with body data:
>>> import urllib
>>> url = 'http://httpbin.org/post'
>>> data = b'userid=fyi&password=center'
>>> r = urllib.request.urlopen(url,data)
>>> b = r.read()
>>> print(b)
b'{\n "args": {}, \n "data": "", \n "files": {}, \n "form": {\n
"password": "center", \n "userid": "fyi"\n }, \n "headers": {\n
"Accept-Encoding": "identity", \n "Connection": "close", \n
"Content-Length": "26", \n
"Content-Type": "application/x-www-form-urlencoded", \n
"Host": "httpbin.org", \n
"User-Agent": "Python-urllib/3.6"\n }, \n
"json": null, \n "url": "http://httpbin.org/post"\n}\n'
⇒ Using urllib.parse.urlencode()
⇐ http.client.HTTPResponse Objects
2018-09-13, ∼2911🔥, 0💬
Popular Posts:
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How to create a "Sign-up or Sign-in" user flow policy in my Azure AD B2C directory? If you want to b...
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
How to create a new API on the Publisher Dashboard of an Azure API Management Service? If you are ne...
How to add an API to an API product for internal testing on the Publisher Portal of an Azure API Man...