diff --git a/400/401.md b/400/401.md index 20eab47..3a5df94 100644 --- a/400/401.md +++ b/400/401.md @@ -23,7 +23,7 @@ requests是一个用于在程序中进行http协议下的get和post请求的库 #get请求 >>> r = requests.get("http://www.itdiffer.com") - + 得到一个请求的实例,然后: >>> r.cookies @@ -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 @@ -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项。喵。