How to write/read/send a data Frame using HTTP/2 in Golang?
Asked Answered
B

1

7

I was wondering how would one go about writing, reading and sending a Frame, for example a Data Frame, using of course HTTP/2. I know Golang library net/http supports this new protocol, but I do not know how to correctly do the above mentioned aspects.

Thank you in advance!

Better answered 11/7, 2016 at 0:3 Comment(0)
O
2

try to send http2 request like this

first of all, you need to import http2 package

import "golang.org/x/net/http2"

then, write some request code

t := &http2.Transport{}
c := &http.Client{
    Transport: t,
}
r, _ := http.NewRequest("GET", "https://http2.golang.org/reqinfo", bytes.NewBuffer([]byte("hello")))
resp, err := c.Do(r)
if err != nil {
    fmt.Printf("request error")
}
defer resp.Body.Close()
content, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("body length:%d\n", len(content))
Okechuku answered 27/10, 2016 at 8:22 Comment(2)
You have not used the Variables 't' and 'r' anywhere after their definition. So why have you defined them ?Nertie
t is used as a Transport in http.Client, r is used in the call c.Do(r) and it represents the request.Keyte

© 2022 - 2024 — McMap. All rights reserved.