python vbs库_Python语言之requests库
發送請求、傳遞URL參數、定制headers、接受數據,處理數據等
在Java中用httpclient jar包,在Python中用requests庫,即使沒有事先下載,在Pycharm開發工具中,出現提示時刻,同意安裝即可
1) 發送請求
url='http://baidu.com'
requests.post(url)
requests.put(url)
requests.delete(url)
requests.head(url)
requests.options(url)
GET: 請求指定的頁面信息,并返回實體主體。
HEAD: 只請求頁面的首部。
POST: 請求服務器接受所指定的文檔作為對所標識的URI的新的從屬實體。
PUT: 從客戶端向服務器傳送的數據取代指定的文檔的內容。
DELETE: 請求服務器刪除指定的頁面。
get 和 post比較常見 GET請求將提交的數據放置在HTTP請求協議頭中
POST提交的數據則放在實體數據中
2) 定制參數
import requests
response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
data={
'name': 'germey',
'age': 22
}
response = requests.get("http://localhost:8083/showuser,param=data}
data2= (
('endDate', '2019-12-12'),
('pageIndex', 0),
('pageSize', 50),
('startDate', '2010-01-01')
)
data3= {
"endDate": "2019-12-12",
"pageIndex": 0,
"pageSize": 50,
"startDate": "2010-01-01"
}
response2=requests.post(url=url2,headers=headers2,data=json.dumps(data2))
response2=requests.post(url=url2,headers=headers2,data=json.dumps(data3))
print(response2.json())
3)定制header
url2='http://localhost:8094/common-api/v1/point/detail?social=AcxiomChina&user=VP巴黎戀人'
headers2={'token':'MTU1Mjg4NTQxOEFDWElPTS1XRUNIQVQ=','Content-Type':'application/json;charset=UTF-8'}
4)response的處理
response.json() 如果是json格式的返回,轉化為json格式
response.cookies
response.status_code
response.url
response.text
response.content
總結
以上是生活随笔為你收集整理的python vbs库_Python语言之requests库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html文字竖直书写,css 文字竖直居
- 下一篇: java中br.readline_jav