我在angualr4 http post请求中有一个奇怪的问题,就是当我使用完整的后端服务器api URL' http://localhost:9090/api/login'邮寄请求没有。但当我使用简单的' / api / login'。使用' http://localhost:4200/api/login'发布请求.below是我的代码
authentication.service.ts
验证(模型){
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")
);
}
答案 0 :(得分:0)