python requests
import requests
类型 | requests方式 |
---|---|
OPTIONS | requests.options |
HEAD | requests.head |
GET | requests.get |
PUT | requests.put |
POST | requests.post |
DELETE | requests.delete |
payload = {'key1': 'value1', 'key2': ['value2', 'value3']}
r = requests.get('http://httpbin.org/get', params=payload)
import json
response = r.text
response = json.loads(response)
response = r.json()
r = requests.get('https://github.com/timeline.json', stream=True)
print(r.raw)
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.post("http://httpbin.org/post", data=payload)
print(r.text)
# output
# {
# ...
# "form": {
# "key2": "value2",
# "key1": "value1"
# },
# ...
# }
payload = {'some': 'data'}
url = 'http://httpbin.org/post'
r = requests.post(url, json=payload)
r = requests.post(url, data=json.dumps(payload))
# output
# {
# "data": "{\"some\": \"data\"}",
# "json": {
# "some": "data"
# }
# }
r.status_code
r.headers