Skip to content

Update p01_interact_with_http_services_as_client.rst #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions source/c11/p01_interact_with_http_services_as_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,18 @@
content_type = resp.headers['content-type']
content_length = resp.headers['content-length']

Here is a requests example that executes a login into the Python Package index using
basic authentication:
下面是一个利用requests通过基本认证登录Pypi的例子:

.. code-block:: python

import requests

resp = requests.get('http://pypi.python.org/pypi?:action=login',
auth=('user','password'))

Here is an example of using requests to pass HTTP cookies from one request to the
next:
下面是一个利用requests将HTTP cookies从一个请求传递到另一个的例子:

.. code-block:: python

import requests

Expand All @@ -133,7 +136,9 @@
# Second requests with cookies received on first requests
resp2 = requests.get(url, cookies=resp1.cookies)

Last, but not least, here is an example of using requests to upload content:
最后但并非最不重要的一个例子是用requests上传内容:

.. code-block:: python

import requests
url = 'http://httpbin.org/post'
Expand Down