Home > Back-end >  Uncaught (promise) in Error: the Network Error
Uncaught (promise) in Error: the Network Error

Time:09-16

A one-piece project, local run the test is no problem, deployed to the server after quote Uncaught (promise) in Error: the Network Error this question,



this is the front end of the code I wrote

 
Axios ({
Method: "POST",
Url: 'http://127.0.0.1:8889/login',
//the type: "json",
Params: {
Username: this username,
Password: this password
},
Headers: {
'the content-type' : 'application/x - WWW - form - urlencoded'
},

{}). Then (function (response)
The console. The log (JSON. Stringify (response. Data));
If (response. Data. Code===200) {
Iview. Modal. Warning ({
Title: "prompt",
Content: the response data. The message
})
window.location.href=https://bbs.csdn.net/topics/response.data.url
}
If (response. Data. Code===500) {
Iview. Modal. Error ({
Title: "prompt",
Content: the response data. The message
})
window.location.href=https://bbs.csdn.net/topics/data.url
}
}). The catch ((e)=& gt; {})


this is the back-end cross-domain code

 
@ Configuration
Public class CorsConfig implements WebMvcConfigurer {
/* private CorsConfiguration buildConfig () {
CorsConfiguration CorsConfiguration=new CorsConfiguration ();
CorsConfiguration. AddAllowedOrigin (" * ");//1 allow any domain name to use
CorsConfiguration. AddAllowedHeader (" * ");//2 allows any head
CorsConfiguration. AddAllowedMethod (" * ");//3 allows any method (post, get, etc.)
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);
}
}


Which big help solve ChongXie. Always has been

CodePudding user response:

https://blog.csdn.net/weixin_42519137/article/details/96003751

CodePudding user response:

https://www.cnblogs.com/sonofdemon/p/12674767.html

CodePudding user response:

Change the front-end
 axios ({
Method: "POST",
Url: 'http://127.0.0.1:8889/login',
//the type: "json",
Params: {
Username: this username,
Password: this password
},
Headers: {
'the content-type' : 'application/x - WWW - form - urlencoded',
'Access - Control - Allow - Origin' : '*'//cors error because request header didn't add information Access - Control - Allow - XXX
},

{}). Then (function (response)
The console. The log (JSON. Stringify (response. Data));
If (response. Data. Code===200) {
Iview. Modal. Warning ({
Title: "prompt",
Content: the response data. The message
})
window.location.href=https://bbs.csdn.net/topics/response.data.url
}
If (response. Data. Code===500) {
Iview. Modal. Error ({
Title: "prompt",
Content: the response data. The message
})
window.location.href=https://bbs.csdn.net/topics/data.url
}
}). The catch ((e)=& gt; {}). The catch ((e)=& gt; {})//uncaught because there is no catch
  • Related