小编Nob*_*iks的帖子

http:服务器向 HTTPS 客户端发出 HTTP 响应

我正在使用 go 来使用 google 地图地理编码 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
Run Code Online (Sandbox Code Playgroud)

错误中的网址在我的浏览器中工作正常并给出适当的响应,但不会在下面的代码片段中给出我想要的内容:

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))
    }
}
Run Code Online (Sandbox Code Playgroud)

go google-geocoding-api

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

go ×1

google-geocoding-api ×1