我是新来尝试angular2
。我已经安装了 angular2 文件上传。我复制了教程中的所有代码here http://valor-software.com/ng2-file-upload/
我完全复制了开发人员在那里写的内容。但我遇到这样的问题:
XMLHttpRequest 无法加载http://localhost:8080/citizen/upload http://localhost:8080/citizen/upload。
对预检请求的响应未通过访问控制检查:
响应中“Access-Control-Allow-Credentials”标头的值
is '' 当请求的凭证模式为 '' 时,该值必须为 'true'
'包括'。起源 'http://本地主机:4200 http://localhost:4200' 因此不允许
使用权。发起请求的凭证模式
XMLHttpRequest 由 withCredentials 属性控制。
我有我的CORS
在我的中像这样过滤SpringBoot
@Component
public class SimpleCorsFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "http://localhost:4200");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Authorization, Content-Type, Accept, enctype");
chain.doFilter(req, res);
}
在我添加 angular2 文件上传代码之前仍然没问题。怎么解决呢?