http:服务器向 HTTPS 客户端提供 HTTP 响应
http: server gave HTTP response to HTTPS client
我正在使用 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
错误中的 url 在我的浏览器中工作正常并给出了适当的响应,但不会在下面的代码片段中给出我想要的:
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))
}
}
问题出在代理上,这可能导致了一些证书问题。没有代理也能正常工作。
我只是将 http.post("https://localhost:8080)
更改为 http.post("http://localhost:8080")
。
只需在 https
中删除一个 s
。
它的工作:-)
我正在使用 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
错误中的 url 在我的浏览器中工作正常并给出了适当的响应,但不会在下面的代码片段中给出我想要的:
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))
}
}
问题出在代理上,这可能导致了一些证书问题。没有代理也能正常工作。
我只是将 http.post("https://localhost:8080)
更改为 http.post("http://localhost:8080")
。
只需在 https
中删除一个 s
。
它的工作:-)