如何解决重定向到外部 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",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后:
我使用代理为客户端和服务器端点提供相同的来源。
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。