我需要使用axios请求从浏览器登录。 问题是没有以某种方式设置cookie。
由于我正在通过javascript文件进行通话, 在浏览器中显示的路径是这样的 文件:/// E:/coding/login-request.html
我正在代码中提供令牌并提出请求 我什至可以登录,并且可以看到已设置的Cookie。
问题是我注销后,令牌的cookie被删除了 然后当我尝试再次登录时。我无法这样做。
现在,为什么会发生这种情况,我该如何解决?
let url = 'https://loginfromhere.co/login';
fetch(url, {
method: "get" ,
mode:'no-cors',
redirect:'follow',
headers:{
'Authorization':'Bearer '+ 'mytokenhere',
},
credentials:'include'
}).then(function(response) {
console.log('response : ',response);
window.location.href = 'https://loginfromhere.co/';
} ).
catch((err)=>{
console.log('err is : ',err);
});
请给出一些想法。
按此顺序发出网络请求 https://loginfromhere.co/login
然后 https://loginfromhere.co/welcome
成功登录后会发生这种情况 在那种情况下,我会在应用程序标签中看到2个cookie Remember_token和会话
,但登录不成功时,即注销后 那么登录尝试后我只会看到一个cookie 那就是会话。
重定向仍然按照我上面显示的顺序进行 但不同之处在于它停留在https://loginfromhere.co/login上 并且不会继续进入欢迎页面。
请告诉我如何解决此问题。我快要解决这个问题了。