Zuul 网关跨域问题

请保证前端允许携带Cookie

出现问题看下面要求:

The value of the Access-Control-Allow-Origin报错

Access-Control-Allow-Headers 不允许使用请求标头字段 Access-Control-Allow-Headers-Java 学习之路

按照上面文章读下来

注意一下:

改动为:

package com.hl.travel.filter;  
  
import org.springframework.http.HttpStatus;  
import org.springframework.stereotype.Component;  
  
import javax.servlet.*;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
import java.io.IOException;  
@Component  
public class Cors implements Filter {  
@Override  
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {  
HttpServletRequest request = (HttpServletRequest) req;  
HttpServletResponse response = (HttpServletResponse) res;  
/* String curOrigin = request.getHeader("Origin");  
System.out.println("###跨域过滤器->当前访问来源->"+curOrigin+"###"); */  
response.setHeader("Access-Control-Allow-Origin",request.getHeader("origin"));  
response.setHeader("Access-Control-Allow-Methods", "*");  
response.setHeader("Access-Control-Max-Age", "3600");  
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");  
response.setHeader("Access-Control-Allow-Credentials", "true");  
  
String method = request.getMethod();  
if ("OPTIONS".equalsIgnoreCase(method)) {  
response.setStatus(HttpStatus.OK.value());  
} else {  
chain.doFilter(req, res);  
}  
}  
@Override  
public void init(FilterConfig filterConfig) {}  
  
@Override  
public void destroy() {}  
}