1、带headers与get参数请求,例子:
import requests
test_url = "http://httpbin.org/get?"
headers = {"test-Agent": "json"}
test_data = {"one": 1, "two": 2}
response = requests.request("GET", test_url, headers=headers, params=test_data)
print(response.text)
2、带headers与post参数请求,例子:
import requests
test_url = "http://httpbin.org/post?"
headers = {"test-Agent": "json"}
test_data = {"one": 1, "two": 2}
response = requests.request("POST", test_url, headers=headers, data=test_data)
print(response.text)
3、带json参数请求,例子:
import json
import requests
test_url = "http://httpbin.org/post?"
headers = {"test-Agent": "json"}
test_json = {
"sits": [
{"name": 1, "url": "http://test1.com"},
{"name": 2, "url": "http://test2.com"}
]
}
response = requests.request("POST", test_url, headers=headers, data=json.dumps(test_json))
print(response.text)