diff options
Diffstat (limited to 'docs/lang')
-rw-r--r-- | docs/lang/python/requests.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/lang/python/requests.py b/docs/lang/python/requests.py new file mode 100644 index 0000000..178a1f7 --- /dev/null +++ b/docs/lang/python/requests.py @@ -0,0 +1,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") |