问题描述
当我尝试为rest api clint运行GO代码时,出现错误:
When I tried to run GO code for rest api clint I got the error:
获取 http://quotes.rest/qod.json :http:连接到代理时出错 http://192.168.0.1:3128/:拨打tcp 192.168.0.1:3128:输入/输出超时
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
我在Go游乐场尝试了相同的代码.也出现错误.
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.
我使用的代码是:-
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))
}
推荐答案
Go Playground不允许HTTP请求.这与代码无关.这是操场强制执行的安全预防措施.
The Go Playground does not allow HTTP requests. This has nothing to do with code. It is a security precaution enforced by the playground.
这篇关于转到错误拨号TCP:协议不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!