dqst96444 2016-05-19 08:02
浏览 68
已采纳

使用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){
  panic(err)
}
req.Header.Add("authorization", fmt.Sprintf("Bearer %s",   access_token))
client := &http.Client{}
res, err := client.Do(req)
if(err != nil){
  panic(err)
}

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.

  • 写回答

1条回答 默认 最新

  • duanrenchuo9244 2016-06-13 01:50
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度