【问题标题】:http: server gave HTTP response to HTTPS clienthttp:服务器对 HTTPS 客户端给出 HTTP 响应
【发布时间】: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。

标签: go google-geocoding-api


【解决方案1】:

问题出在代理上,这可能导致一些证书问题。没有代理也能正常工作。

【讨论】:

    【解决方案2】:

    我只是将http.post("https://localhost:8080) 更改为http.post("http://localhost:8080")。 只需删除https 中的s。 它的工作:-)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 2021-10-07
    • 2018-09-15
    • 2021-04-27
    • 2021-04-19
    • 1970-01-01
    • 2019-12-05
    相关资源
    最近更新 更多