0

i cant connect my localhost api . my environment.ts is:

export const environment = {
production: false,
apiUrl: 'http://127.0.0.1/slimapp/api/'
};

my httpservice:

post(serviceName: string, data: any) {
const headers = new HttpHeaders().set( 'Content-Type', 'application/json' );
const options = { headers: headers, withCredintials: false };
const url = environment.apiUrl + serviceName;

return this.http.post(url, JSON.stringify(data), options);
}

my login service is :

login(postData: any): Observable<any> {
return this.httpService.post('login', postData);
}

my connection where is my page.ts is:

this.authService.login(this.postData).subscribe(
    (res: any) => {
      if (res.userData) {
        // Storing the User data.
        this.storageService.store(AuthConstants.AUTH, res.userData);
        this.storage.set('user_id', res.userData.id);
        this.storage.set('name',res.userData.name);

        this.router.navigate(['home/orders']);
      } else {
        this.alertService.presentAlert('','Yanlış Kullanıcı Adı ya da Şifre!');
      }
    },
    (error: any) => {
      this.alertService.presentAlert('',"Hata Oluştu");
      this.toastService.presentToast(error.json())
    }
  );

when i console error, the output is enter image description here How can i do it?

Mustafa UYSAL
  • 143
  • 3
  • 14
  • Two things...first for your console.error wrap the thing you are trying to read in JSON.stringify. This will allow you to read the actual object. Second, since you are able to see console, you should also be able to click on the output line and use the call stack to set a break point. alternatively you could add 'debugger;' to your code and force a break point at the console.error line and inspect the values that way. Let me know the results and if you have any issues and I'll update my comments or otherwise provide an answer. –  May 21 '20 at 12:17
  • I edited the output picture. can you look at it – Mustafa UYSAL May 21 '20 at 12:29
  • Do you have a server running on port 80? Can you access that url directly from the browser. It is possible this has nothing to do with your code. –  May 21 '20 at 12:32
  • i can access on fiddler and postman. – Mustafa UYSAL May 21 '20 at 12:40
  • Are there any errors in your server log. It is possible you need to add options. { headers: { 'Content-Type': 'application/json', } } –  May 21 '20 at 12:46
  • Does this answer your question? [I get "Http failure response for (unknown url): 0 Unknown Error" instead of actual error message in Angular](https://stackoverflow.com/questions/47180634/i-get-http-failure-response-for-unknown-url-0-unknown-error-instead-of-actu) –  May 21 '20 at 16:37
  • I do solutions but nothing is gone work – Mustafa UYSAL May 22 '20 at 07:24

0 Answers0