0

when i m calling an api by providing wrong credential i m getting an error response in postman. but when the same is called by angular i m getting different error status.

 login(loginFormData){
    this.service.login(loginFormData.value.username,loginFormData.value.password).subscribe((res:any)=>{      
      if(res.status.code == 1){
        this.route.navigate(['/dashboard'], { replaceUrl: true });
      }
    },
    (err) => {
      console.log(err);
      this.errorMsg = "Oops!!Something went wrong.";
    });
  }
}

this is the response which i m getting through postman enter image description here

1 Answer 1

1

It is expected and working via postman is postman doesn't send preflight requests while your browser does.You can fix it in two ways,

Solution 1 - you need to change your backend to accept your incoming requests

Solution 2 - using Angular proxy see here

Sign up to request clarification or add additional context in comments.

5 Comments

I m getting the expected output in postman.But my query is why i m not gettting the same error response in log?
cant you see it in the answer why its working in postman? do you know about CORS?
Its hitting my webServices also , there is no need to set proxy
Yes bro, through ui its hitting the same webService
I am repeating the same again. Read about developer.mozilla.org/en-US/docs/Web/HTTP/CORS here, thats your issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.