i have strange issue in angualr4 http post request ,that is when i use full backend server api URL 'http://localhost:9090/api/login' post request did not make. but when i use simply '/api/login'. post request made with 'http://localhost:4200/api/login' .below is my code
authentication.service.ts
authenticate(model) {
console.log('this.globalConstant.apiLoginURL',this.globalConstant.apiLoginURL);
console.log('this.apiLoginURL',this.apiLoginURL);
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers }); // Create a request option
let bodyString = JSON.stringify(model); // Stringify payload
console.log('headers==>'+headers);
console.log('options==>'+options);
console.log('bodyString==>'+bodyString);
return this.http.post(this.endpoint+'/api/login', bodyString, options)
.map(this.extractData)
.catch(this.handleError);
}
login.component.ts
login() {
this.newsDataService.authenticate(this.account)
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
},
error => {
this.alertService.error(error);
console.log('alertService==>'+error);
},
() => console.log("Finished")
);
}