python3+requests:get/post请求
生活随笔
收集整理的這篇文章主要介紹了
python3+requests:get/post请求
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.get請求
(1)沒有請求參數類型
1 response = requests.get(url='') 2 print(response.text)(2)有請求參數的類型(鍵值對形式表示參數)
1 response = requests.get(url='',params={'key1':'value1','key2':'value2'}) 2 print(response.text)(3)有請求頭(鍵值對形式表示請求頭)
1 response = requests.get(url='',headers={'key1':'value1'}) 2 print(response.text)2.post請求
(1)請求正文是application/x-www-form-urlencoded
1 requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'application/x-www-form-urlencoded'})(2)請求正文是multipart/form-data
1 requests.post(url='',data={'key1':'value1','key2':'value2'},headers={'Content-Type':'multipart/form-data'})(3)請求正文是raw
傳入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'})或者
1 requests.post(url='',json={{'key1':'value1','key2':'value2'}},headers={'Content-Type':'application/json'})(4)請求正文是binary
1 requests.post(url='',files={'file':open('test.xls','rb')},headers={'Content-Type':'binary'})?轉載請注明出處:https://www.cnblogs.com/shapeL/p/9037035.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的python3+requests:get/post请求的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 刚怀孕要做什么检查吗(刚怀孕要做什么检查
- 下一篇: 花呗十号还款算逾期吗?10号当天还款可以