【发布时间】:2017-09-14 07:01:59
【问题描述】:
我有一个 angular2 应用程序,它击中了一个 api,它位于我的 wamp/www 中。当我尝试点击 api 时出现此错误。
404 未找到
未找到
在此服务器上找不到请求的 URL /usmanproject/api/web/v1/users。
Apache/2.4.9 (Win64) PHP/5.5.12 服务器在 localhost 端口 80
我的 Angular 应用程序正在 localhost:4200 上运行,并且 Angular 项目文件夹也放置在 wamp/www 中,但它无法正常工作。
这是我的角码
private heroesUrl = 'http://localhost/usmanproject/api/web/v1/users?access-token=n-EJtZiejtz5RSVWe-U14G4kCnPWMKf0'; // URL to web api
private headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
create(): Promise<any> {
return this.http
.get(this.heroesUrl)
.toPromise()
.then(res => res.json().data)
.catch(this.handleError);
}
后端是在yii2 中制作的。我已经在邮递员中测试了apihttp://localhost/usmanproject/api/web/v1/users?access-token=n-EJtZiejtz5RSVWe-U14G4kCnPWMKf0,它在那里工作得非常好。
它在 google chrome 中运行良好,但在 firefox 上却不行。
【问题讨论】:
-
你的 api 是否在 80 端口上运行?
-
不,不是。它只是像这样简单地运行 localhost/usmanproject/api/web/v1/users?access-token=n-EJtZiejtz5RSVWe-U14G4kCnPWMKf0
-
您没有告诉我们有关您的后端的任何信息,因此只能猜测并提出其他问题。你应该至少包含一些关于你验证后端真的在你写的 URL 上运行的信息。
-
让我写吧
-
你是否在 web Api 中启用了“cors”
标签: angular api http localhost port