Javascript 在跨源http请求中添加所有cookie
我想跨源发送GET请求,但浏览器仅附加一些cookie,而不是全部cookie。 例如,如果我使用HTML表单发送请求,那么它也会附加跨源的所有cookieJavascript 在跨源http请求中添加所有cookie,javascript,browser,request,xmlhttprequest,cross-origin-read-blocking,Javascript,Browser,Request,Xmlhttprequest,Cross Origin Read Blocking,我想跨源发送GET请求,但浏览器仅附加一些cookie,而不是全部cookie。 例如,如果我使用HTML表单发送请求,那么它也会附加跨源的所有cookie <html> <body> <script>history.pushState('', '', '/')</script> <form action="https://www.example.com/api/invites" method="
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="https://www.example.com/api/invites" method="GET" enctype="text/plain">
<input type="submit" value="Submit request" />
</form>
</body>
</html>
history.pushState(“”,“/”)
如果我使用这个,浏览器会在请求中删除会话cookie
<html>
<body>
<button type="button" onclick="snt()">Submit</button>
<script type="text/javascript">
function snt(){
var request = new XMLHttpRequest();
request.onreadystatechange= function () {
if (this.readyState==4) {
//var a = this.responseText;
request.open("GET","http:\/\/www.example2.com\/?a=122", true);
request.send();
}
}
request.open("GET", "https:\/\/www.example.com\/api\/invites", true);
request.withCredentials = true;
request.send();
}
</script>
</form>
</body>
</html>
提交
函数snt(){
var request=new XMLHttpRequest();
request.onreadystatechange=函数(){
if(this.readyState==4){
//var a=this.responseText;
打开(“GET”,“http:\/\/www.example2.com\/?a=122”,true);
request.send();
}
}
打开(“GET”,“https:\/\/www.example.com\/api\/invests”,true);
request.withCredentials=true;
request.send();
}
任何建议,使我可以做同样的事情与任何语言或与这一个