一個一體式專案,本地運行測驗都沒有問題,部署到服務器上以后就報Uncaught (in promise) Error: Network Error這個問題。

這是我寫的前端代碼
axios({
method: 'POST',
url: 'http://127.0.0.1:8889/login',
//type:"jsonp",
params:{
username:this.username,
password:this.password
},
headers: {
'Content-Type':'application/x-www-form-urlencoded'
},
}).then(function (response) {
console.log(JSON.stringify(response.data));
if (response.data.code===200){
iview.Modal.warning({
title:"提示",
content:response.data.message
})
window.location.href=https://bbs.csdn.net/topics/response.data.url
}
if(response.data.code===500){
iview.Modal.error({
title:"提示",
content:response.data.message
})
window.location.href=https://bbs.csdn.net/topics/data.url
}
}).catch((e)=>{})
這是后端跨域代碼
@Configuration
public class CorsConfig implements WebMvcConfigurer {
/*private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 允許任何域名使用
corsConfiguration.addAllowedHeader("*"); // 2 允許任何頭
corsConfiguration.addAllowedMethod("*"); // 3 允許任何方法(post、get等)
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", buildConfig()); // 4
return new CorsFilter(source);
}*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.allowCredentials(true)
.allowedHeaders("*")
.maxAge(3600);
}
}
哪位大佬幫忙解決必有重謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/48129.html
標籤:Java EE
