Angular2 - http://localhost:4200/被附加了 api 调用为什么? [英] Angular2 - http://localhost:4200/ being appended with api call why?
本文介绍了Angular2 - http://localhost:4200/被附加了 api 调用为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
跟着heroes
教程开始学习angular2
.我正在发出创建请求,URL 很好,参数也很好.但是我仍然很困惑为什么 http://localhost:4200/
被附加到我的 API
调用中,因此 URL 完全改变了,并且调用失败了.请对此问题有所了解.我用谷歌搜索了很多,但找到了原因.
just start learning angular2
followed the heroes
tutorial. I am making a create request, the URL is perfectly fine, the parameters are fine. But I am still confused why http://localhost:4200/
is being appended with my API
call, and because of that the URL gets totally changed, and the calls failed.please shed some light over this issue. I googled a lot but could find the reason.
我的创建方法
create(user: object): Promise<any> {
return this.http
.post('localhost/usmanProject/api/web/v1/users?access-token=n-EJtZiejtz5RSVWe-U14G4kCnPWMKf0', user, { headers: this.headers })
.toPromise()
.then(res => res.json().data)
.catch(this.handleError);
}
推荐答案
您需要为您的 URL 添加协议.否则,它是一个相对 URL:
You need to add your protocol for your URL. Otherwise, it's a relative URL:
.post('http://localhost/usmanProject/api/web/v1/users?access-token=n-EJtZiejtz5RSVWe-U14G4kCnPWMKf0', user, { headers: this.headers })
这篇关于Angular2 - http://localhost:4200/被附加了 api 调用为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文