以下是api的文档:
curl -g "https://api.com" \
-H "Authorization: Bearer $api-key" \
-H "Accept: application/vnd.api+json"
这就是我所拥有的。并且它不起作用。请帮忙。任何建议将不胜感激。我是Web开发的新手,但真的很喜欢。
var request = new XMLHttpRequest();
request.open("GET", "https://api.com", false);
request.setRequestHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9");
requset.setRequestHeader("Accept", "application/vnd.api+json");
request.send();
var response = JSON.parse(request.responseText);
var thetables = document.getElementById("Main");
var row = document.createElement("tr");
var cell1 = document.createElement("td");
var cellText = document.createTextNode(namez);
cell1.appendChild(cellText)
var cell2 = document.createElement("td");
var cellText1 = document.createTextNode(response[0]);
cell2.appendChild(cellText1)
var cell3 = document.createElement("td");
var cellText2 = document.createTextNode(response[1]);
cell3.appendChild(cellText2)
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3)
thetables.appendChild(row);
答案 0 :(得分:0)
有关“ setRequestHeader”的用法,请参见https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader。 您需要传递2个参数,而不仅仅是传递1个参数。即:
request.setRequestHeader("Authorization", "Bearer $eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9");