Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
48 changes: 43 additions & 5 deletions 48 400/401.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ requests是一个用于在程序中进行http协议下的get和post请求的库
#get请求

>>> r = requests.get("http://www.itdiffer.com")

得到一个请求的实例,然后:

>>> r.cookies
Expand All @@ -39,10 +39,10 @@ requests是一个用于在程序中进行http协议下的get和post请求的库

>>> r.headers
{'x-powered-by': 'PHP/5.3.3', 'transfer-encoding': 'chunked', 'set-cookie': 'PHPSESSID=buqj70k7f9rrg51emsvatveda2; path=/', 'expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'keep-alive': 'timeout=15, max=500', 'server': 'Apache/2.2.15 (CentOS)', 'connection': 'Keep-Alive', 'pragma': 'no-cache', 'cache-control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'date': 'Mon, 10 Nov 2014 01:39:03 GMT', 'content-type': 'text/html; charset=UTF-8', 'x-pingback': 'http://www.1world0x00.com/index.php/action/xmlrpc'}

>>> r.encoding
'UTF-8'

>>> r.status_code
200

Expand Down Expand Up @@ -83,11 +83,49 @@ requests发送post请求,通常你会想要发送一些编码为表单的数

r没有加data的请求,看看效果:

![](http://wxpictures.qiniudn.com/requets-post1.jpg)
```json
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "0",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.4.3 CPython/2.7.8 Windows/7"
},
"json": null,
"origin": "58.246.118.137",
"url": "http://httpbin.org/post"
}
```

r1是加了data的请求,看效果:

![](http://wxpictures.qiniudn.com/requets-post2.jpg)
```json
{
"args": {},
"data": "",
"files": {},
"form": {
"key1": "value1",
"key2": "value2"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "23",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.4.3 CPython/2.7.8 Windows/7"
},
"json": null,
"origin": "58.246.118.139",
"url": "http://httpbin.org/post"
}
```

多了form项。喵。

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.