【发布时间】:2015-04-25 12:27:29
【问题描述】:
在我的 Nodejs 服务器上下订单后,我正尝试重定向到支付网关,但我的浏览器都不允许我这样做。
这是我的代码,它直接来自我的支付服务的代码示例。
res.writeHead(302, { Location : payment.getPaymentUrl() });
res.end();
这总是导致:
XMLHttpRequest cannot load https://www.mollie.com/payscreen/pay/CtcH7nkDQr. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1337' is therefore not allowed access.
我已将我的应用配置为使用那里的标题:
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Access-Control-Max-Age", "3600");
next();
});
【问题讨论】:
-
当我在浏览器中转到
https://www.mollie.com/payscreen/pay/CtcH7nkDQr,然后从 Chrome 开发人员工具网络选项卡中检查标头时,我看不到任何标头。这是我得到的完整标题:HTTP/1.1 200 OK Server: nginx Date: Tue, 24 Feb 2015 00:46:24 GMT Content-Type: text/html Content-Length: 2142 Connection: keep-alive Strict-Transport-Security: max-age=15552000 X-XSS-Protection: 1; mode=block X-Frame-Options: DENY Vary: Accept-Encoding Content-Encoding: gzip X-Whom: dc1-web-3它实际上似乎是 nginx,甚至不是 nodejs。也许?