问题
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