W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
為了最大程度地控制通過網(wǎng)絡(luò)發(fā)送的內(nèi)容,HTTPX 支持構(gòu)建顯式請(qǐng)求實(shí)例:
request = httpx.Request("GET", "https://example.com")
要將實(shí)例分派到網(wǎng)絡(luò),請(qǐng)創(chuàng)建一個(gè)Client實(shí)例并使用? Request.send()
?:
with httpx.Client() as client:
response = client.send(request)
...
如果需要以默認(rèn)的參數(shù)合并不支持的方式混合?client-level
?和?request-level
?選項(xiàng),可以使用?.build_request()
?,然后對(duì)?Request
?實(shí)例進(jìn)行任意修改。例如:
headers = {"X-Api-Key": "...", "X-Client-ID": "ABC123"}
with httpx.Client(headers=headers) as client:
request = client.build_request("GET", "https://api.example.com")
print(request.headers["X-Client-ID"]) # "ABC123"
# Don't send the API key for this particular request.
del request.headers["X-Api-Key"]
response = client.send(request)
...
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: