简体   繁体   English

无法在Golang的http2中使用流式传输

[英]fail to use streaming in http2 in golang

How to reuse http2 stream in golang? 如何在golang中重用http2流?

Hi all, recently I tried many ways to reuse a stream to send http2 data but failed, and I didn't find many related solutions in http2, can anyone give me some hints or demos? 大家好,最近,我尝试了多种方法来重用流来发送http2数据,但是失败了,并且在http2中找不到很多相关的解决方案,有人可以给我一些提示或演示吗?

client := http.Client{

        Transport: &http2.Transport{
            DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
                return net.DialTimeout(network, addr, time.Second)
            },
                AllowHTTP: true,
        },
    }

    resp, err := client.Get(path)

I tried to use resp as client and write to this resp to send data to server. 我尝试使用resp作为客户端,并写入此resp以将数据发送到服务器。 Is it right way to do it? 这是正确的方法吗?

In HTTP/2 streams are short lived, and correspond to a request/response exchange. 在HTTP / 2中,流是短暂的,并且对应于请求/响应交换。 In effect the end of the response closes the stream. 实际上,响应结束会关闭流。 Issuing another request via client.Get will automatically open a new stream on the connection, if the underlying connection is using HTTP/2. 如果基础连接使用HTTP / 2,则通过client.Get发出另一个请求, client.Get将自动在连接上打开一个新流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM