{"id":207367,"date":"2025-07-08T10:00:21","date_gmt":"2025-07-08T02:00:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207367\/"},"modified":"2025-07-08T10:00:21","modified_gmt":"2025-07-08T02:00:21","slug":"%e4%bd%bf%e7%94%a8-go-%e5%90%91-mojang-api-%e5%8f%91%e5%87%ba%e8%af%b7%e6%b1%82%e4%bc%9a%e8%bf%94%e5%9b%9e-403","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207367\/","title":{"rendered":"\u4f7f\u7528 go \u5411 mojang API \u53d1\u51fa\u8bf7\u6c42\u4f1a\u8fd4\u56de 403"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u4f7f\u7528 go \u5411 mojang API \u53d1\u51fa\u8bf7\u6c42\u4f1a\u8fd4\u56de 403<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-21 23:09:38<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2aGolang\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u4f7f\u7528 go \u5411 mojang API \u53d1\u51fa\u8bf7\u6c42\u4f1a\u8fd4\u56de 403\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u5bf9 golang \u5f88\u964c\u751f\uff0c\u4f46\u6211\u6b63\u5728\u5c1d\u8bd5\u5411 mojang api \u53d1\u51fa http get \u8bf7\u6c42\u4ee5\u83b7\u53d6\u73a9\u5bb6\u59d3\u540d\u7684 uuid\u3002\u8fd9\u662f\u6211\u7684\u4ee3\u7801\u3002<\/p>\n<pre>func gethttp(url string) (response string) {\n\n    client := &amp;http.client{}\n\n    req, err := http.newrequest(\"get\", url, nil)\n    req.header.add(\"content-type\", \"application\/json\")\n    if err != nil {\n        return string(err.error())\n    }\n\n    resp, err := client.do(req)\n    if err != nil {\n        return string(err.error())\n    }\n\n    defer resp.body.close()\n\n    body, e := ioutil.readall(resp.body)\n    if err != nil {\n        return string(e.error())\n    }\n\n    return string(body)\n}\n\nfunc main() {\n  fmt.printf(gethttp(\"https:\/\/api.mojang.com\/users\/profiles\/minecraft\/paultje52\"))\n}\n<\/pre>\n<p>\u6211\u5f97\u5230\u7684\u662f\u4e00\u4e2a\u5e26\u6709 403 \u9519\u8bef\uff08\u8bf7\u6c42\u88ab\u963b\u6b62\uff09\u7684 html \u6587\u6863\uff0c\u5c31\u50cf\u60a8\u5728\u6b64\u5904\u770b\u5230\u7684\u90a3\u6837\u3002<\/p>\n<pre>&lt;!doctype html public \"-\/\/w3c\/\/dtd html 4.01 transitional\/\/en\" \"http:\/\/www.w3.org\/tr\/html4\/loose.dtd\"&gt;\n&lt;html&gt;&lt;head&gt;&lt;meta http-equiv=\"content-type\" content=\"text\/html; charset=iso-8859-1\"&gt;\n&lt;title&gt;error: the request could not be satisfied&lt;\/title&gt;\n&lt;\/head&gt;&lt;body&gt;\n&lt;h1&gt;403 error&lt;\/h1&gt;\n&lt;h2&gt;the request could not be satisfied.&lt;\/h2&gt;\n&lt;hr noshade size=\"1px\"&gt;\nrequest blocked.\nwe 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.\n&lt;br clear=\"all\"&gt;\nif you provide content to customers through cloudfront, you can find steps to troubleshoot and help prevent this error by reviewing the cloudfront documentation.\n&lt;br clear=\"all\"&gt;\n&lt;hr noshade size=\"1px\"&gt;\n&lt;pre&gt;\ngenerated by cloudfront (cloudfront)\nrequest id: jxluo2auflong500lqbzeswb0yksv4ae8dreo3g-0arxxmjsfs5c8g==\n&lt;\/pre&gt;\n&lt;address&gt;\n&lt;\/address&gt;\n&lt;\/body&gt;&lt;\/html&gt;\n<\/pre>\n<p>\u4f46\u662f\u5f53\u6211\u4f7f\u7528 google chrome \u6216 postman\uff08\u5177\u6709\u76f8\u540c ip \u7684\u540c\u4e00\u53f0\u673a\u5668\uff09\u8bbf\u95ee\u5b8c\u5168\u76f8\u540c\u7684 url \u65f6\uff0c\u6211\u4f1a\u4ece mojang api \u5f97\u5230\u6b63\u5e38\u54cd\u5e94\u3002<\/p>\n<pre>{\n    \"name\": \"Paultje52\",\n    \"id\": \"895933a3f98b4bd697515673a04d632e\"\n}<\/pre>\n<p>\u6211\u505a\u9519\u4e86\u4ec0\u4e48\u6216\u8005\u8fd9\u662f go \u7684\u95ee\u9898\u5417\uff1f\u6216\u8005\u963b\u6b62 go \u53d1\u51fa\u7684 cloudfront \u8bf7\u6c42\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u8be5\u7f51\u7ad9\u4f3c\u4e4e\u963b\u6b62\u4e86\u9ed8\u8ba4\u7528\u6237\u4ee3\u7406\u3002 \u4f7f\u7528\u4ee5\u4e0b\u884c\u66f4\u6539\u5b83\uff0c\u4e00\u5207\u90fd\u4f1a\u6b63\u5e38\u5de5\u4f5c<\/p>\n<pre>req.Header.Set(\"User-Agent\", \"test\")<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u4f7f\u7528 go \u5411 mojang API \u53d1\u51fa\u8bf7\u6c42\u4f1a\u8fd4\u56de 403\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207367","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207367"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207367\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}