The same request, when I use Postman to initiate the request, Fiddler displays it as http1.1 protocol, but when I look at the requests listed by Network in Chrome browser, it displays as http2. I successfully requested in Chrome browser and Postman, but failed in Python. I tried to initiate an http2 request using the httpx library, but still couldn’t make the request successfully.
import json
import httpx
client = httpx.Client(http2=True)
url = "https://api.dhldanhao.com/waybill/listForCodes"
payload = {
"page_size": "",
"begin_time": "1722960000",
"end_time": "",
"types": "USPS",
"codes": "41035",
"sn_status": "1",
"start_address": ""
}
headers = {
'accept': 'application/json, text/plain, */*',
'accept-language': 'zh-CN,zh;q=0.9',
'access-control-allow-origin': '*',
'content-type': 'application/json',
'origin': 'https://www.dhldanhao.com',
'priority': 'u=1, i',
'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
}
response = client.request("POST", url, headers=headers, content=json.dumps(payload))
print(response.http_version)
print(response.text)
The above is Python code, and the response is a 403 status code.
But I found in Postman that the actual request address is an IPv6 address.