有什么理由要写吗
corsFilter.setAllowedOrigins(new HashSet<String>(Arrays.asList("*")));
其中ReSTLet框架中allowedOrigins
的定义为
private Set<String> allowedOrigins = SetUtils.newHashSet("*");
另一个问题 - 当我编写上面的行时,我在运行我的应用程序时遇到错误。 由于某种原因,我得到了重复的来源,并且客户端拒绝接受它 - 在请求中我可以看到“*”和我发送请求的域名。
这种重复是如何发生的,处理它的最佳方法是什么?
最佳答案
您是对的,无需提供此值,因为它已经是默认值。你能告诉我你在哪里读到必须设置这样的值吗?
我不明白你问题的第二部分到底发生了什么,因为我无法重现它(使用 CorsFilter 或 CorsService)。
您可以尝试改用 CorsService 吗?该服务有助于配置 Cors 功能,并集成在应用程序或组件的服务列表中,例如在应用程序的构造函数中:
public TestCorsApplication() {
CorsService corsService = new CorsService();
corsService.setAllowedCredentials(true);
corsService.setSkippingResourceForCorsOptions(true);
getServices().add(corsService);
}
关于java - CorsFilter setAllowedOrigins(*) 冗余,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31556560/