W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
為了最大程度地控制通過網(wǎng)絡(luò)發(fā)送的內(nèi)容,HTTPX 支持構(gòu)建顯式請求實例:
request = httpx.Request("GET", "https://example.com")
要將實例分派到網(wǎng)絡(luò),請創(chuàng)建一個Client實例并使用? Request.send()
?:
with httpx.Client() as client:
response = client.send(request)
...
如果需要以默認的參數(shù)合并不支持的方式混合?client-level
?和?request-level
?選項,可以使用?.build_request()
?,然后對?Request
?實例進行任意修改。例如:
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號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: