这个报错通常情况下会出现在请求跨域。
先让后端解决一下,其实就是设置下请求头部:
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
String orignalHeader = request.getHeader("Origin");
if (orignalHeader != null ) {
Matcher m = CORS_ALLOW_ORIGIN_REGEX.matcher(orignalHeader);
if (m.matches()) {
response.addHeader("Access-Control-Allow-Origin", orignalHeader);
response.addHeader("Access-Control-Allow-Credentials", "true");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
response.addHeader("Access-Control-Allow-Headers", "x-dataplus-csrf, Content-Type");
}
}
}
但是,很遗憾,没有用。
因为这个报错,是出现在发出请求之前的,所以改后台应该没什么用。
那么问题出在哪里?
要注意到最后一句报错:Redirect is not allowed for a preflight request.大致意思就是在预请求的时候不允许重定向。
重定向???
请求一个接口怎么还重定向了呢?百撕不得骑姐。
最后,想到,这个接口是有登录认证的。
简单的说,就是这个接口需要事先登录,拿到token。当没有登录时,这个接口自然被重定向到login界面。
所以,就出现了上边的“Redirect”。