2016-05-19 08:02

使用Go使用http / 2连接到Alexa语音服务时遇到问题


I am trying to establish a downchannel as described here under Creating an http/2 connection. I am writing my client in Go, and my code is as follows:

api_endpoint := "https://avs-alexa-na.amazon.com/v1/directives"
access_token := fetchAccessToken() //retrieves token from local file
req, err := http.NewRequest("GET", api_endpoint, nil)
if(err != nil){
req.Header.Add("authorization", fmt.Sprintf("Bearer %s",   access_token))
client := &http.Client{}
res, err := client.Do(req)
if(err != nil){

The problem is that my client gives the following error after the request: Get https://avs-alexa-na.amazon.com/v1/directives: malformed HTTP response "\x00\x00\x1e\x04\x00\x00\x00\x00\x00\x00\x01\x00\x00\x10\x00\x00\x03\x00\x00\x00".

I am not sure how to deal with this. I suspect that Go is not using http/2 for some reason, and thus cannot handle the response, but I don't know why that would be the case. I am using Go 1.6.1, which should use it automatically. Any help would be greatly appreciated.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanrenchuo9244 duanrenchuo9244 5年前

    It turns out the problem was a bug in Go 1.6.1 which caused HTTP clients to not use http/2 by default. Upgrading to 1.6.2 solved the problem. Github Issue: https://github.com/golang/go/issues/14391

    点赞 评论 复制链接分享