expected result image; please view it for better understanding:
Please find below code; when a user clicks on button I get all the HTTP headers except Authroization Header without which I can not get the response so I hardcoded it with xhttp.setRequestHeader ('Authorization', 'Bearer')
but I need its value; each user will have different authorization value.
Please find all the headers in snapshot.
I have hard coded the Authorization header in code.
<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>
I want to add only cookie `[test_token] value into Authorization header; after adding the test_token the header should look like 'Authorization: Bearer test_token' The cookie should be added into authorization header prior to showing the response.