Tools, FAQ, Tutorials:
urllib.request.Request Properties and Functions
What properties and functions are supported on urllib.request.Request objects?
✍: FYIcenter.com
urllib.request.Request objects support the following properties and functions:
>>> q = urllib.request.Request(url) host # represents the host name of the url. type # represents the internet protocol type of the url. full_url # represents the url method # represents the method of the request. headers # represents user added headers header_items() # returns all headers add_header() # adds more headers data # represents the body of the request as binary >>> dir(q) ['__class__', ..., 'add_header', 'add_unredirected_header', 'data', 'fragment', 'full_url', 'get_full_url', 'get_header', 'get_method', 'has_header', 'has_proxy', 'header_items', 'headers', 'host', 'method', 'origin_req_host', 'remove_header', 'selector', 'set_proxy', 'timeout', 'type', 'unredirected_hdrs', 'unverifiable']
Here is a Python example showing urllib.request.Request properties:
>>> import urllib
>>> url = 'http://httpbin.org/post'
>>> form = {'user':'fyicenter', 'msg':'hello world!'}
>>> data = urllib.parse.urlencode(form)
>>> data = bytes(data,'utf8')
>>> headers = { 'Referer' : 'http://dev.fyicenter.com' }
>>> q = urllib.request.Request(url,data,headers,method='POST')
>>> q.method
'POST'
>>> q.type
'http'
>>> q.host
'httpbin.org'
>>> q.headers
{'Referer': 'http://dev.fyicenter.com'}
>>> q.data
b'user=fyicenter&msg=hello+world%21'
⇒ Sending FTP Request with urllib.request.urlopen
⇐ Using urllib.request.Request Object
2018-09-13, ∼2717🔥, 0💬
Popular Posts:
Where Is the Submitted Form Data Stored in PHP? When a user submit a form on your Web server, user e...
Where to find tutorials on Visual Studio? I want to know How to learn Visual Studio. Here is a large...
Why am I getting this "Docker failed to initialize" error? After installing the latest version of Do...
What Happens If One Row Has Missing Columns? What happens if one row has missing columns? Most brows...
What is EPUB 3.0 Metadata "dcterms:modified" property? EPUB 3.0 Metadata "dcterms:modified" is a req...