【发布时间】:2019-11-05 15:41:47
【问题描述】:
请在下面找到代码;当用户单击按钮时,我会获得除授权标头之外的所有 HTTP 标头,没有这些标头我无法获得响应,因此我使用 xhttp.setRequestHeader ('Authorization', 'Bearer') 对其进行硬编码,但我需要它的值;每个用户将有不同的授权值。
请在快照中找到所有标题。
我已经在代码中硬编码了 Authorization 标头。
<html>
<body>
<button type='button' onclick='cors()'>CORS</button>
<p id='demo'></p>
<script>
function cors() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var a = this.responseText;
document.getElementById("demo").innerHTML = a;
xhttp.open("POST", "http://xyz . com", true);
xhttp.withCredentials = true;
console.log(a);
xhttp. send("data="+a);
}
};
xhttp.open("GET", "https://api. xyz. com/v1/users/", true);
xhttp.withCredentials = true;
xhttp.setRequestHeader("Authorization", "Bearer ");
xhttp.send();
}
</script>
</body>
</html>
我只想将 cookie `[test_token] 值添加到授权标头中;添加 test_token 后,标头应类似于“授权:承载 test_token” 在显示响应之前,应将 cookie 添加到授权标头中。
【问题讨论】:
标签: javascript ajax