python+requests+new——get请求各种情况
import requests
urls = 'http://httpbin.org/get'
a='k1'
b='v1'
c='k2'
d='v2'
response = requests.get(url=urls, params={a: b,c:d})
print(response.status_code)
print(response.url)
执行结果:
200
http://httpbin.org/get?k1=v1&k2=v2
=======================================================================================================
import requests urls = 'http://httpbin.org/get' payload001 = {'k1':'v1','k2':'v2'} response = requests.get(url=urls, params=payload001) print(response.status_code) print(response.url)
执行结果:
200
http://httpbin.org/get?k1=v1&k2=v2
=====================================================================================================
import requests urls = 'http://httpbin.org/get' payload002 = {'key1': 'value1', 'key2': ['value2', 'value3']} response = requests.get(url=urls, params=payload002) print(response.status_code) print(response.url)
执行结果:
200
http://httpbin.org/get?key1=value1&key2=value2&key2=value3
========================================================================================
定制请求体:
urls = 'https://api.github.com/some/endpoint'
payload002 = {'key1': 'value1', 'key2': ['value2', 'value3']}
headersl = {'user-agent': 'my-app/0.0.1'} response = requests.get(url=urls, headers=headersl, params=payload002)
========================================================================================