开始测试

首先测试 requests

测试代码

import requests

# 发起 HTTP GET 请求
url = "http://xxx.xxx.xxx.xxx:8086"


response = requests.get(url)

# 打印结果
print("Response Content (bytes):", response.content)
print("Response Text (str):", response.text)

服务端收到的请求头

{
    "host": "xxx.xxx.xxx.xxx:8086",
    "user-agent": "python-requests/2.31.0",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br",
    "connection": "close"
}

测试 httpx

测试代码

import httpx


# 发起 HTTP GET 请求
url = "http://xxx.xxx.xxx.xxx:8086"


with httpx.Client() as client:
    response = client.get(url)

# 打印结果
print("Response Content (bytes):", response.content)
print("Response Text (str):", response.text)

服务端收到的请求头

{
    "host": "xxx.xxx.xxx.xxx:8086",
    "user-agent": "python-httpx/0.24.0",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br",
    "connection": "close"
}

最后测试 curl_cffi

测试代码

from curl_cffi import requests

# 发起 HTTP GET 请求
url = "http://xxx.xxx.xxx.xxx:8086"


response = requests.get(url)

# 打印结果
print("Response Content (bytes):", response.content)
print("Response Text (str):", response.text)

服务端收到的请求头

{
    "host": "xxx.xxx.xxx.xxx:8086",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br, zstd"
}

universe_king
3.4k 声望680 粉丝