Python httpx库如何发送HTTP/2 POST请求?-灵析社区

momo

httpx 怎么发一个 post http2 请求 `curl --http2-prior-knowledge -X POST http://127.0.0.1:1313 -d 'ww$$go'` 这个 curl 是有效的,但怎么使用 httpx 来实现 with httpx.Client(http2=True,verify=False) as client: res = client.post('http://127.0.0.1:1313',data=b'dtest') print("res",res) # 试了几次都不对

阅读量:12

点赞量:0

问AI
import httpx url = "http://127.0.0.1:1313" data = "ww$$go" headers = { "Content-Type": "application/x-www-form-urlencoded", # 设置合适的 Content-Type } # 使用 httpx 发送 HTTP/2 POST 请求 with httpx.Client(http2=True) as client: response = client.post(url, data=data, headers=headers) # 输出响应信息 print(f"Status Code: {response.status_code}") print("Response Content:") print(response.text)