【发布时间】:2019-03-18 02:39:42
【问题描述】:
我正在构建一个 WordPress woocommerce 支付插件,以及一个在 Nodejs 后端服务器中用于连接的 API。
我正在使用 curl 正常调用 API ('https://test.com/test'):
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => json_encode($body)
));
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
然后在我的 API 中,我必须接收并检查 POST 参数,然后重定向到另一个路由器 ('https://test.com/render) 以呈现 ejs 视图页面。 我尝试使用
res.redirect(307, 'https://test.com/test')
或
res.writeHead(307, { 'Location': 'https://test.com/test' });
res.end();
或者直接渲染页面
res.render('index', { merchantUser: UserID });
甚至
window.location.href = 'https://test.com/test'
但是前三个直接返回NULL,最后一个返回'window not defined'。而且它们都没有到达重定向路由器('https://test.com/render)。
我在网上能找到的就这些了,谁能帮帮我或者给我一些建议?非常感谢。
【问题讨论】:
-
你能显示你的代码来接收你想要重定向的api吗
-
@mooga 在我的问题中,我尝试了 res.redirect()、res.writeHead()、res.render()。在此之前,我只是收集数据并检查它们是否有效。