闲来无事,登录了练习平台找了个简单题练手,涉及到了新的内容,记录一下。
现象:
网页和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()
文章讲述了在遇到使用Postman和代码发送http请求返回403错误时,发现是后端基于http2.0请求进行了判断。通过Charles工具确认了这一情况,并展示了在Python中使用httpx库启用http2.0进行请求的方法。
9907

被折叠的 条评论
为什么被折叠?



