标签:处理 mamicode 现象 utils bee ade tps work scan
1、问题现象
Access to XMLHttpRequest at ‘http://yyyy‘ from origin ‘http://zzzz‘ has been blocked by CORS policy: Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response.
在上图中“Provisional headers are shown”是指显示了临时的请求头,这种现象的产生是当浏览器第一次发送这个请求时请求被阻塞,并未收到响应;而浏览器再次发送这个请求时,由于上一个同样的请求都还没有收到响应,浏览器就会报这个警告。总之来说,就是请求并没有发送出去。
2、问题分析
3、问题处理
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringEscapeUtils; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.stereotype.Component; @Component @ServletComponentScan @WebFilter(urlPatterns = "/*", filterName = "httpFilter") public class HttpFilter implements Filter { @Override public void init(FilterConfig filterConfig) { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Headers", "*"); filterChain.doFilter(servletRequest, servletResponse); } @Override public void destroy() { } }
标签:处理 mamicode 现象 utils bee ade tps work scan
原文地址:https://www.cnblogs.com/bien94/p/13188699.html