登录
首页 >  Golang >  Go问答

服务器向客户端发送了HTTP响应

来源:stackoverflow

时间:2024-03-01 19:57:21 222浏览 收藏

今日不肯埋头,明日何以抬头!每日一句努力自己的话哈哈~哈喽,今天我将给大家带来一篇《服务器向客户端发送了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

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

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即可。 它的工作:-)

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>