闲来无事,登录了练习平台找了个简单题练手,涉及到了新的内容,记录一下。
现象:
网页和charles重放可以拿到返回结果,通过postman和代码请求403或者其他
原因
后端进行了http2.0请求判断,非http2.0不通过
如何分辨
http1.1:以百度为例,在source-> requests headers -> view source显示
http2.0:如图所示
python如何进行htttp2.0的请求
import httpx
data = {}
headers={
'method': 'POST',
'authority': '',
'scheme': 'https',
'path': '/api/challenge24',
'sec-ch-ua': '"Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
'accept': 'application/json, text/javascript, */*; q=0.01',
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'x-requested-with': 'XMLHttpRequest',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
'sec-ch-ua-platform': '"Windows"',
'origin': '',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': '',
'accept-encoding': 'gzip, deflate, br',
}
client = httpx.Client(http2=True)
res = client.post(url="", headers=headers, data=data).json()
client.close()
标签:ch,headers,初体验,sec,ua,fetch,http2.0
From: https://www.cnblogs.com/FlowerNotGiveYou/p/17149762.html