How to send a POST request to an HTTP2 with Hyper

时间:2018-03-25 20:20:36

标签: python request http2 hyper

I just want to send a post request to submit a form to a website who only use h2 protocol.

import requests
from hyper.contrib import HTTP20Adapter
import hyper

session = requests.session()

session.mount(url, HTTP20Adapter())

r = session.post(url, data=payload, headers=header)


print(r.text)

This doesn't seem to work. And since Hyper documentation is pretty empty. I needed some external help.

Thank you in advance

1 个答案:

答案 0 :(得分:0)

我认为这是hyper库中的错误(已通过Release v0.7.0.测试)。我对原始hyper库有同样的问题,必须设置Content-Length查询头。没有此标头hyper,HTTP / 2不会发送查询主体。使用HTTP / 1.1时,无需设置Content-Length标头即可正常工作。

它被报告为错误: https://github.com/Lukasa/hyper/issues/320