1.get請求html
(1)沒有請求參數類型json
1 response = requests.get(url='') 2 print(response.text)
(2)有請求參數的類型(鍵值對形式表示參數)app
1 response = requests.get(url='',params={'key1':'value1','key2':'value2'}) 2 print(response.text)
(3)有請求頭(鍵值對形式表示請求頭)post
1 response = requests.get(url='',headers={'key1':'value1'}) 2 print(response.text)
2.post請求url
(1)請求正文是application/x-www-form-urlencodedspa
1 requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'application/x-www-form-urlencoded'})
(2)請求正文是multipart/form-datacode
1 requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'multipart/form-data'})
(3)請求正文是raworm
傳入xml格式文本
1 requests.post(url='',data='<?xml ?>',headers={'Content-Type':'text/xml'})
傳入json格式文本
1 requests.post(url='',data=json.dumps({'key1':'value1','key2':'value2'}),headers={'Content-Type':'application/json'})
或者xml
1 requests.post(url='',json={{'key1':'value1','key2':'value2'}},headers={'Content-Type':'application/json'})
(4)請求正文是binaryhtm
1 requests.post(url='',files={'file':open('test.xls','rb')},headers={'Content-Type':'binary'})