http2.0 发送请求

import json

import httpx
# 注意要安装 pip install h2
data = {
  'page': '2'
}
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',
}
cookies ={
}
max_count = 0
for i in range(1,101):
    client = httpx.Client(http2=True)
    try:
      data = {
            'page': str(i)
      }
      res = client.post(url="", headers=headers, data=data,
                        cookies=cookies).json()
      count = res['data']
      num_list = sum([int(i['value']) for i in count])
      max_count += num_list
      print('----------')
      print(num_list)
      print(max_count)
      print('----------')
    finally:
        client.close()

"""
import requests
from hyper.contrib import HTTP20Adapter
data = {
  'page': '2'
}
sessions=requests.session()
sessions.mount('首页地址', HTTP20Adapter())
res=sessions.get('url',headers=headers,data=data,verify=False,cookies=cookies).content
print(res)
"""

  

posted @ 2021-10-18 15:14  Mr_Smith  阅读(532)  评论(0编辑  收藏  举报