go error dial tcp: Protocol not available

家住魔仙堡 提交于 2019-12-12 05:39:13

问题


When I tried to run GO code for rest api clint I got the error:

Get http://quotes.rest/qod.json: http: error connecting to proxy http://192.168.0.1:3128/: dial tcp 192.168.0.1:3128: i/o timeout

further I tried the same code in Go playground. There also error appeared.

What may be the reason? How can I solve this? Please help me to solve this issue.

The code I used is:-

package main

import(
    "net/http"
    "fmt"
    "io/ioutil"
)

func main() {

    resp, er := http.Get("http://quotes.rest/qod.json")
    if er!=nil{
            fmt.Println(er)
            return
        }
    defer resp.Body.Close()
    content, err := ioutil.ReadAll(resp.Body)
    if err!=nil{
            fmt.Println(err)
            return
        }
    fmt.Println(string(content))
}

回答1:


The Go Playground does not allow HTTP requests. This has nothing to do with code. It is a security precaution enforced by the playground.



来源:https://stackoverflow.com/questions/44727653/go-error-dial-tcp-protocol-not-available

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!