我正在使用 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)