【发布时间】:2019-06-07 05:21:05
【问题描述】:
我正在使用 go 使用谷歌地图地理编码 API,但我不断收到此错误:
The HTTP request failed with error Get https://maps.googleapis.com /maps/api/geocode/json?address=Bangalore&key=KEY: http: server gave HTTP response to HTTPS client
错误中的 url 在我的浏览器中可以正常工作并给出适当的响应,但不会在下面的代码 sn-p 中给出我想要的:
package main
import(
"fmt"
"io/ioutil"
"net/http"
)
func main() {
key := "mysecretkey"
location := "Bangalore"
url := "https://maps.googleapis.com/maps/api/geocode/json?address="+location+"&key="+key
fmt.Println("Starting the application...")
response, err := http.Get(url)
if err!=nil{
fmt.Printf("The HTTP request failed with error %s\n", err)
}else {
data, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(data))
}
}
【问题讨论】:
-
尝试将 URL 中的 https 更改为 http
-
我最终得到了这个:
{ "error_message" : "Requests to this API must be over SSL. Load the API with \"https://\" instead of \"http://\".", "results" : [], "status" : "REQUEST_DENIED" } -
您这边出了点问题。当我在本地运行时,您的代码运行良好。您使用的是哪个 Go 版本?
-
这是
go version的输出:go1.12.5 linux/amd64 -
这应该只是工作(tm)。您是否使用了代理?并坚持使用 Go 1.12。不再支持 1.9。