mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Issue #25570: Merge add_header() example from 3.5
This commit is contained in:
commit
f9de40666c
1 changed files with 6 additions and 1 deletions
|
@ -189,7 +189,7 @@ The following classes are provided:
|
||||||
|
|
||||||
*headers* should be a dictionary, and will be treated as if
|
*headers* should be a dictionary, and will be treated as if
|
||||||
:meth:`add_header` was called with each key and value as arguments.
|
:meth:`add_header` was called with each key and value as arguments.
|
||||||
This is often used to "spoof" the ``User-Agent`` header, which is
|
This is often used to "spoof" the ``User-Agent`` header value, which is
|
||||||
used by a browser to identify itself -- some HTTP servers only
|
used by a browser to identify itself -- some HTTP servers only
|
||||||
allow requests coming from common browsers as opposed to scripts.
|
allow requests coming from common browsers as opposed to scripts.
|
||||||
For example, Mozilla Firefox may identify itself as ``"Mozilla/5.0
|
For example, Mozilla Firefox may identify itself as ``"Mozilla/5.0
|
||||||
|
@ -1111,6 +1111,9 @@ HTTPErrorProcessor Objects
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
In addition to the examples below, more examples are given in
|
||||||
|
:ref:`urllib-howto`.
|
||||||
|
|
||||||
This example gets the python.org main page and displays the first 300 bytes of
|
This example gets the python.org main page and displays the first 300 bytes of
|
||||||
it. ::
|
it. ::
|
||||||
|
|
||||||
|
@ -1220,6 +1223,8 @@ Use the *headers* argument to the :class:`Request` constructor, or::
|
||||||
import urllib.request
|
import urllib.request
|
||||||
req = urllib.request.Request('http://www.example.com/')
|
req = urllib.request.Request('http://www.example.com/')
|
||||||
req.add_header('Referer', 'http://www.python.org/')
|
req.add_header('Referer', 'http://www.python.org/')
|
||||||
|
# Customize the default User-Agent header value:
|
||||||
|
req.add_header('User-Agent', 'urllib-example/0.1 (Contact: . . .)')
|
||||||
r = urllib.request.urlopen(req)
|
r = urllib.request.urlopen(req)
|
||||||
|
|
||||||
:class:`OpenerDirector` automatically adds a :mailheader:`User-Agent` header to
|
:class:`OpenerDirector` automatically adds a :mailheader:`User-Agent` header to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue