admin管理员组文章数量:1321440
I can store the jwt token in local storage, but i don't know how to send it as a bearer token back to my restful api endpoint and i just can't find this information anywhere. How could i do that using only xmlhttprequest?
I can store the jwt token in local storage, but i don't know how to send it as a bearer token back to my restful api endpoint and i just can't find this information anywhere. How could i do that using only xmlhttprequest?
Share Improve this question asked Oct 7, 2018 at 3:30 lucaspcblucaspcb 812 silver badges6 bronze badges 1-
1
xhr.setRequestHeader('Authorization', 'Bearer ' + jwtoken);
– Jaromanda X Commented Oct 7, 2018 at 3:32
3 Answers
Reset to default 4This can be done by using setRequestHeader()
function. This function is using to set the value of an HTTP request header. When using setRequestHeader()
, you must call it after calling open(), but before calling send()
. If this method is called several times with the same header, the values are merged into one single request header.
function initXMLHttpRequest(method, url, jwtoken){
let xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open(method, url);
xmlHttpRequest.setRequestHeader('Authorization', 'Bearer ' + jwtoken);
return xmlHttpRequest;
}
It could be possible.
xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("jwtoken"))
Set authorization header in your xmlhttprequest.
req.setRequestHeader("Authorization", token);
本文标签: javascriptHow to send jwt in xmlhttprequestStack Overflow
版权声明:本文标题:javascript - How to send jwt in xmlhttprequest? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742100737a2420789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论