-
Notifications
You must be signed in to change notification settings - Fork 11
/
20.py
28 lines (24 loc) · 772 Bytes
/
20.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
url= 'http://httpbin.org'
r= requests.get(url)
print 'Response object properties and methods available'
print dir(r)
print 'URL, response code, response text, headers and redirection history'
print r.url
print r.status_code
print r.text
print r.headers
print r.history
print 'Making requests with parameters - GET and POST'
payload= {'key':'value'}
headers = {'user-agent': 'my-app/0.0.1'}
cookies = dict(cookies_are='working')
r = requests.get('http://httpbin.org/get', params = payload, cookies=cookies)
print r.status_code
r = requests.post('http://httpbin.org/post', data = payload, headers=headers)
print r.status_code
print r.json()
print r.headers.get('content-type')
jar = requests.cookies.RequestsCookieJar()
print dir(jar)
print jar.values()