使用密钥和密钥发送授权的GET HTTP请求

时间:2018-02-14 15:57:07

标签: javascript api xmlhttprequest

目前我正在尝试向此网址发送HTTP请求,

https://api.earn.gg/account/get?key=6c7ca4b2-96f2-4e23-8156-9aff64d84e67&secret=1a98b15357b2c5530e5e60b33bd2952c

但是我收到一条错误消息,表示未经授权,我需要发送标题

Failed to load https://api.earn.gg/account/get?key=6c7ca4b2-96f2-4e23-8156-9aff64d84e67&secret=1a98b15357b2c5530e5e60b33bd2952c: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

无论如何我可以使用授权访问权限访问此API,当我将它放在我的浏览器中时,它会返回我的帐户信息,有什么方法可以在javascript中修复此问题吗? 我的代码:

<button onclick="dothing()">Grab</button>
<script>
function dothing() {
request = new XMLHttpRequest()
    url = "https://api.earn.gg/account/get?key=6c7ca4b2-96f2-4e23-8156-9aff64d84e67&secret=1a98b15357b2c5530e5e60b33bd2952c"
    request.open("GET", url, false); // false for synchronous request
request.send(null);
print(request.responseText)
}

</script>

0 个答案:

没有答案