【发布时间】:2017-07-27 02:32:00
【问题描述】:
我正在向具有以下路由的服务器发出请求:
app.use('/401', (req, res) => res.status(401).end());
app.use('/403', (req, res) => res.status(403).end());
app.use('/404', (req, res) => res.status(404).end());
app.use('/500', (req, res) => res.status(500).end());
app.use('/502', (req, res) => res.status(502).end());
app.use('/503', (req, res) => res.status(503).end());
app.use('/504', (req, res) => res.status(504).end());
当我向 Angular(/404、{})提出请求时:
public async post(path: string, data: object): Promise<Response> {
try {
return await this.http.post(path, data).toPromise();
} catch (err) {
console.log('err', err);
throw err;
}
}
我明白了:
ok: false
status: 0
statusText: ""
type: 3
在 Chrome 控制台中,我看到请求是使用 OPTIONS 发出的,它确实返回了 404:
Request URL: http://localhost:3000/404/
Request Method: OPTIONS
Status Code: 404 Not Found
它去哪儿了?怎样才能得到真正的错误码?
我读到这可能是 CORS 问题...我的应用程序在 4200 上,我的服务在 3000 上。在我的服务中,我在顶部(在其他任何东西之前):
app.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Credentials", "true");
res.setHeader("Access-Control-Allow-Methods", "*");
res.setHeader("Access-Control-Allow-Headers", "*");
next();
});
我认为这不是 COR 的问题...
但我不知道,会不会?
我不应该得到状态为404 的err 吗?
【问题讨论】:
标签: angular angular-http