node.js - 重定向到外部 url 并使用 express 和 react 将数据作为正文参数发送
问题描述
我在前端有一个表单,它将数据发布到后端的API。然后,我向它添加额外的参数,即私钥并创建一个JSON 对象。在此之后,我必须在传递 JSON 对象进行付款时重定向到外部 URL(Payumoney)。
我无法将数据添加为查询参数,因为它包含敏感信息。
App.js(表单)
<form action="/api/payumoney" method="POST">
<label>
FirstName:
<input type="text" name="firstname" onChange={handleChange} value={formValue.firstname} />
</label>
<label>
TxnID:
<input type="text" name="txnid" onChange={handleChange} value={formValue.txnid} />
</label>
<label>
Amount:
<input type="text" name="amount" onChange={handleChange} value={formValue.amount} />
</label>
<label>
ProductInfo:
<input type="text" name="productinfo" onChange={handleChange} value={formValue.productinfo} />
</label>
<label>
Email:
<input type="email" name="email" onChange={handleChange} value={formValue.email} />
</label>
<input type="submit" value="Submit" />
</form>
index.js
app.post("/api/payumoney", urlencodedParser, (req,res) => {
const pd = req.body; //JSON Object that we've to parse to the external URL
const url = "https://sandboxsecure.payu.in/_payment";
//Here goes something that can redirect to the URL and pass the JSON object
}
index.js(使用请求)——它完成重定向并将数据传递给它的工作,但支付功能不起作用(附图片)
app.post("/api/payumoney", urlencodedParser, (req,res) => {
const pd = req.body; //JSON Object that we've to parse to the external URL
const url = "https://sandboxsecure.payu.in/_payment";
request.post({
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
uri: 'https://sandboxsecure.payu.in/_payment', //Testing URL
form: pd,
}, function (error, httpRes, body) {
if (error){
console.log("Error",error);
res.status(400).json(
{
status: false,
message: error
}
);
}
if (httpRes.statusCode === 200) {
res.send(body);
} else if (httpRes.statusCode >= 300 && httpRes.statusCode <= 400) {
res.redirect(httpRes.headers.location.toString());
console.log("error 300 and 400");
}
})
}
使用请求解析数据并重定向到 Payumoney URL 后:
我正在使用代理来为客户端和服务器端点提供相同的来源。
谢谢!
解决方案
推荐阅读
- php - ajax响应仅显示jquery和php中数据库的最后一行?
- python - 没有为任何变量提供梯度,检查你的图表中不支持梯度的操作,变量和损失之间
- javascript - Javascript make 方法在帖子完成时运行
- android - 如何在 Ionic APP 中将相同的 CSS 应用到 Android 和 IOS
- excel - 如何获取存储在本地 OneDrive 文件夹中的 Excel 工作簿的路径+文件名?(与其网址相反!)
- python - 打破基本python的循环
- jenkins - 通过 kubernetes 部署稳定的 jenkins 图表时出错:curl 默认执行 SSL 证书验证
- pandas - 如何使用聚合合并熊猫中的特定列值
- ide - 手机有编译器吗?
- java - 导入项目时出现以下错误。某些项目可能无法加载