先描述下出现的问题:此时我的前后端未分离项目需要访问另一个后端项目的接口,此时调用接口却报了一个类似跨域的问题。
Access to XMLHttpRequest at 'http://localhost:8888/process/list?order=asc' from origin 'http://localhost:8099' has been blocked by CORS policy: Request header field x-csrf-token is not allowed by Access-Control-Allow-Headers in preflight response.
大致的意思就是"x-csrf-token"这个请求头参数不被允许发送的意思。
此时我们就要在后端服务器的跨域配置过滤器里修改下允许访问的请求头参数
response.setHeader("Access-Control-Allow-Headers", "Content-Type,x-requested-with, authorization, x-csrf-token");
修改完毕后重启下后端项目,再次请求,可以访问成功!