记录一个跨域问题,之前一直是在后端解决跨域的,但是今天出了个问题,所以记录一下。
Access to XMLHttpRequest at 'localhost:8443/api/user/login' from origin 'http://localhost:8080' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
后端代码
@Configuration
public class CroConfig implements WebMvcConfigurer {
/**
* 解决跨域问题
*
* @param registry
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
.allowCredentials(true)
.maxAge(3600)
.allowedHeaders("*");
}
}
前端配置
axios.defaults.baseURL = "localhost:8443/api"
在前端配置baseURL的时候需要加上协议
axios.defaults.baseURL = "http://localhost:8443/api"
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/su_zui/article/details/122801715
内容来源于网络,如有侵权,请联系作者删除!