blob: 178a1f75ce73326321d7d40c4f1c5984eb033483 (
plain) (
blame)
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
|
import requests
import json
# GET
r = requests.get("https://httpbin.org/get?a=b&c=d")
print(r.headers)
print(r.text)
# POST
r = requests.post("https://httpbin.org/post",
data={'a': 'b', 'c': 'd'})
# POST JSON
r = requests.post("https://httpbin.org/post",
json={'a': 'b', 'c': 'd'})
print(r.json())
# Request headers
r = requests.get("https://httpbin.org/get",
headers={'DNT': '1'}) # Do not track
# Session (any cookies obtained will be saved/sent with follow-up requests)
s = requests.Session()
r = s.post("...",
data={'username': '...', "password": '...'})
r = s.get(".../my_user_data")
|