使用 go 向 mojang API 发出请求会返回 403
来源:stackoverflow
2024-04-21 23:09:38
0浏览
收藏
对于一个Golang开发者来说,牢固扎实的基础是十分重要的,golang学习网就来带大家一点点的掌握基础知识点。今天本篇文章带大家了解《使用 go 向 mojang API 发出请求会返回 403》,主要介绍了,希望对大家的知识积累有所帮助,快点收藏起来吧,否则需要时就找不到了!
问题内容
我对 golang 很陌生,但我正在尝试向 mojang api 发出 http get 请求以获取玩家姓名的 uuid。这是我的代码。
func gethttp(url string) (response string) { client := &http.client{} req, err := http.newrequest("get", url, nil) req.header.add("content-type", "application/json") if err != nil { return string(err.error()) } resp, err := client.do(req) if err != nil { return string(err.error()) } defer resp.body.close() body, e := ioutil.readall(resp.body) if err != nil { return string(e.error()) } return string(body) } func main() { fmt.printf(gethttp("https://api.mojang.com/users/profiles/minecraft/paultje52")) }
我得到的是一个带有 403 错误(请求被阻止)的 html 文档,就像您在此处看到的那样。
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>error: the request could not be satisfied</title> </head><body> <h1>403 error</h1> <h2>the request could not be satisfied.</h2> <hr noshade size="1px"> request blocked. we can't connect to the server for this app or website at this time. there might be too much traffic or a configuration error. try again later, or contact the app or website owner. <br clear="all"> if you provide content to customers through cloudfront, you can find steps to troubleshoot and help prevent this error by reviewing the cloudfront documentation. <br clear="all"> <hr noshade size="1px"> <pre> generated by cloudfront (cloudfront) request id: jxluo2auflong500lqbzeswb0yksv4ae8dreo3g-0arxxmjsfs5c8g==