According to the api docs, your code should be something like this:
(根据api文档,您的代码应如下所示:)
<script>
var summonername = "TraversTT";
var api_key1= "RGAPI-1ed86c58-2eee-4e6c-85d4-3bead97e4d3b";
var headers1 = {
'X-Riot-Token': "RGAPI-1ed86c58-2eee-4e6c-85d4-3bead97e4d3b",
}
var settings = {
"async": true,
"type": "GET",
"url": "https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/"+summonername+"?api_key="+api_key1,
"headers": headers1,
};
$.ajax(settings).done(function (response) {
console.log(response);
});
</script>
There are different types of HTTP requests;
(HTTP请求有不同的类型。)
GET, POST, PUT, etc... You were using POST
but that endpoint only supports GET
and you were setting some headers that are typically response headers.(GET,POST,PUT等...您正在使用POST
但是该端点仅支持GET
并且您正在设置一些标头,通常是响应标头。)
Unfortunately there is a CORS issue on this endpoint, so your browser will not be able to access it via your browser.
(不幸的是,此端点上存在CORS问题,因此您的浏览器将无法通过浏览器访问它。)
You can try this cUrl
in your terminal to see the response (copy and paste this into your terminal):
(您可以在终端中尝试此cUrl
以查看响应(将其复制并粘贴到终端中):)
curl 'https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/TraversTT?api_key=RGAPI-1ed86c58-2eee-4e6c-85d4-3bead97e4d3b' -X OPTIONS -H 'Access-Control-Request-Method: GET' -H 'Origin: https://js-9vpefs.stackblitz.io' -H 'Referer: https://js-9vpefs.stackblitz.io/' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36' -H 'DNT: 1' -H 'Access-Control-Request-Headers: x-riot-token' --compressed
Note
(注意)
I will suggest never to post your API key ( 'X-Riot-Token': "RGAPI-1ed86c58-2eee-4e6c-85d4-3bead97e4d3b"
) on a public forum.
(我建议不要在公共论坛上发布您的API密钥( 'X-Riot-Token': "RGAPI-1ed86c58-2eee-4e6c-85d4-3bead97e4d3b"
)。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…