我尝试使用js代码来获取远程(spring boot)js代码,它显示了
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://45.82.79.208/ with MIME type text/plain. See https://www.chromestatus.com/feature/5629709824032768 for more details
我的js代码:
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://45.82.79.208/";
document.head.appendChild(script);
我的 spring boot 代码,允许 cros:
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // allow cros path
.allowedOrigins("*") // allow cros origin
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")// allow method
.maxAge(168000) //
.allowedHeaders("*")
.allowCredentials(true);
}
}
我的代码有问题吗?如何解决此问题以允许 CORS?
最佳答案
根据the page ,响应类型不正确。可以尝试设置js的响应头(content-type)
它将阻止从 或 标记请求的跨源文本/html 响应,并将其替换为空响应
关于java - 如何解决Spring Boot应用程序中的CORS问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58677850/