Python httpx库如何发送HTTP/2 POST请求?

Python httpx库如何发送HTTP/2 POST请求?

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)

# 试了几次都不对


回答:

python">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)

以上是 Python httpx库如何发送HTTP/2 POST请求? 的全部内容, 来源链接: utcz.com/p/939100.html

回到顶部