【发布时间】:2017-08-25 20:45:37
【问题描述】:
我的 Angular 2 应用程序在 8100 端口上运行,而 API 项目是使用节点构建的,并且在不同的端口 3003 上运行。API 项目不是休息 API 项目。
当我尝试从 Rest Client 或 Postman 调用 API 之一时,我收到了响应。
即使尝试从节点调用 API,它也可以正常工作。
从 Angular 2 项目进行 API 调用时,它显示 404 错误。
Angular 2 代码 -
getApplications() {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('cache-control', 'no-cache');
headers.append('Access-Control-Allow-Origin', '*');
return this.http.post('http://localhost:3003/applications/list', {}, {})
.map(res => res.json());
}
NodeJS 工作请求 -
var request = require("request");
var options = {
method: 'POST',
url: 'http://localhost:3003/application/list',
headers:
{
'cache-control': 'no-cache',
'content-type': 'application/json'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
邮递员请求 -
【问题讨论】:
标签: angular localhost cross-domain