+
80
-

js中跨域请求如何携带cookie信息?

js中跨域请求如何携带COOKIE信息?

网友回复

+
0
-

三种方法:

1、前端请求时在request对象中配置"withCredentials": true;

    axios({
      withCredentials: true, // ++ 新增
      method: "get",
      url: "http://localhost:8003/anotherService",
    }).then((res) => {
      console.log(res);
    });

2、服务端在response的header中配置"Access-Control-Allow-Origin", "http://域名:端口号";

3、服务端在response的header中配置"Access-Control-Allow-Credentials", "true"

我知道答案,我要回答