這篇文章主要講解了“Requests三種參數(shù)請求方式介紹”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Requests三種參數(shù)請求方式介紹”吧!
創(chuàng)新互聯(lián)總部坐落于成都市區(qū),致力網(wǎng)站建設(shè)服務(wù)有網(wǎng)站設(shè)計、網(wǎng)站制作、網(wǎng)絡(luò)營銷策劃、網(wǎng)頁設(shè)計、網(wǎng)站維護(hù)、公眾號搭建、成都微信小程序、軟件開發(fā)等為企業(yè)提供一整套的信息化建設(shè)解決方案。創(chuàng)造真正意義上的網(wǎng)站建設(shè),為互聯(lián)網(wǎng)品牌在互動行銷領(lǐng)域創(chuàng)造價值而不懈努力!
URL參數(shù)請求:
import requests
'''
URL Parameters 請求方式:URL參數(shù)
例如: 以get 方式請求http://httpbin.org/get?first_name=hello&last_name=word
'''
# params={"first_name":"hello","last_name":"word"}
# responds=requests.get("http://httpbin.org/get",params=params)
# print(responds.text)
# print(responds.url)
表單參數(shù)請求:
'''
表單參數(shù)提交,注意只更新的是表單數(shù)據(jù)
Content-Type: application/x-www-form-urlencoded
例如: 以post 方式請求http://httpbin.org/post, 增加的資源為params={"first_name":"hello","last_name":"word"}
'''
params={"first_name":"hello","last_name":"word"}
headers={"Content-Tpye":"application/x-www-form-urlencoded"}
responds=requests.post("http://httpbin.org/post",data=params,headers=headers)
print(responds.text)
print(responds.url)
print(responds.request)
Json 參數(shù)數(shù)據(jù)請求
'''
Json數(shù)據(jù)提交,更新的是數(shù)據(jù)data
Content-Type: application/json
例如: 以post 方式請求http://httpbin.org/post, 增加的資源為params={"first_name":"hello","last_name":"word"}
'''
#Python學(xué)習(xí)交流QQ群:778463939
params={"first_name":"hello","last_name":"word"}
headers={"Content-Tpye":"application/json"}
responds=requests.post("http://httpbin.org/post",json=params,headers=headers)
print(responds.text)
print(responds.url)
print(responds.request)
額外話題--構(gòu)建URL
def build_url(URL,endpoint):
return "/".join([URL,endpoint])
print(build_url("http://httpbin.org","post"))
感謝各位的閱讀,以上就是“Requests三種參數(shù)請求方式介紹”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Requests三種參數(shù)請求方式介紹這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
分享名稱:Requests三種參數(shù)請求方式介紹
標(biāo)題鏈接:http://chinadenli.net/article28/ppgecp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、App開發(fā)、ChatGPT、響應(yīng)式網(wǎng)站、建站公司、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)