英文:
go error dial tcp: Protocol not available
问题
当我尝试运行用于 REST API 客户端的 GO 代码时,我遇到了以下错误:
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 Playground 中尝试了相同的代码,也出现了错误。
可能的原因是什么?我该如何解决这个问题?请帮助我解决这个问题。
我使用的代码是:
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))
}
英文:
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
得分: 3
Go Playground不允许进行HTTP请求。这与代码无关,而是Playground强制执行的安全预防措施。
英文:
The Go Playground does not allow HTTP requests. This has nothing to do with code. It is a security precaution enforced by the playground.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论