我尝试使用 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?
手掌心
蓝山帝景
相关分类