Search code examples
gohttp2alexa-voice-service

Having trouble connecting to Alexa Voice Service with http/2 using Go


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.


Solution

  • 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