私は ionic を初めて使用します。質問がばかげている場合はご容赦ください。開発中、ブラウザを使用してアプリケーションを表示およびテストしていますが、すべてが問題なく完全に機能していますが、Android デバイスの Ionic DevApp でアプリケーションをテストすると、アプリケーションはバックエンドと通信できません ( REST API)。要求 (ログイン要求など) を送信するたびに、システムは応答し[object progressevent]ます。
エラーメッセージを表示する console.log:
[ng] [console.log]: {
[ng] "headers": {
[ng] "normalizedNames": {},
[ng] "lazyUpdate": null,
[ng] "headers": {}
[ng] },
[ng] "status": 0,
[ng] "statusText": "Unknown Error",
[ng] "url": "http://localhost:8080/restapi/api/user/login",
[ng] "ok": false,
[ng] "name": "HttpErrorResponse",
[ng] "message": "Http failure response for http://localhost:8080/restapi/api/user/login: 0 Unknown Error",
[ng] "error": {
[ng] "isTrusted": true
[ng] }
[ng] }
私のアプリケーション:
フロントエンド: Ionic + Angular
バックエンド (REST API): Java Spring MVC、Oracle Developer Database、Hibernate
さまざまなオンライン リソースを検索して解決策を見つけようとしましたが、残念ながら、他の人が提供した解決策は私のシナリオでは機能しません。したがって、私はこの質問を投稿して、イオンの専門家からの助けを求めています。ありがとうございました。
ログイン要求の私のコード:
this.http.login(this.user)
.subscribe((userData: any) => {
console.log('Success login');
this.http.storeToken(userData.token);
this.loginForm.reset();
this.errorMessageService.setValidationErrorMessage('');
this.exceptionHandlerService.setErrorResponse('');
console.log(userData);
this.router.navigate(['']);
},
error => {
if (this.exceptionHandlerService.getErrorResponse() === null || this.exceptionHandlerService.getErrorResponse() === '') {
console.log(error);
this.exceptionHandlerService.setErrorResponse(error.error);
}
console.log(error);
});
ログインサービスの私のコード:
userUrl = 'http://localhost:8080/restapi/api/user/';
login(user: User) {
const body = JSON.stringify(user);
return this.http.post<User>(this.userUrl + 'login', body, httpOptions);
}