我正在 Angular 版本 7 中集成支付网关。
支付网关需要输入如下数据
requestParameter : MerchantId||CollaboratorID||Encrypted_string
我尝试使用 ngForm 提交表单,如下所示,但我的请求没有发布到支付网关 url 并收到错误 404 未找到“http://localhost:4200/direcPayment/”和支付网关的 session 过期消息作为响应。就像如果请求中有任何错误,您会收到 session 过期消息。
<form (ngSubmit)="onSubmit()" method="POST" mt-3>
在代码后面,我根据需要传递参数并进行 http.post 调用,如下所示。单击 OnSubmit 后,我使用加密字符串调用了 formSubmit
formSubmit( encryptedString) {
const formData = new FormData();
formData.append( 'requestParameter', encryptedString);
this.http.post('direcPayment/', formData, httpFormDataOptions)
.subscribe((resposne) => {
console.log(resposne);
});
}
在“httpFormDataOptions”中,我在标题下方添加了
const httpFormDataOptions = {
headers: new HttpHeaders(),
};
httpFormDataOptions.headers.append('Access-Control-Allow-Origin', '*');
httpFormDataOptions.headers.append('Access-Control-Allow-Methods', 'DELETE, POST, GET, OPTIONS');
httpFormDataOptions.headers.append('Access-Control-Allow-Headers', 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
/direcPayment 指的是我的 Proxy.config.json 文件如下
{
"/direcPayment": {
"target": "PaymentGatewayURL",
"secure": true,
"pathRewrite": {"^/direcPayment" : ""},
"changeOrigin": true
},
}
所以目前我使用 ngNoForm 并使用 action 属性提交表单。
所以我想问两个问题
谢谢。
最佳答案
您的代码:
this.http.post('direcPayment/', formData, httpFormDataOptions)
.subscribe((resposne) => {
console.log(resposne);
});
}
所以post数据会提交到
http://localhost:4200/direcPayment/
, 你应该把你的支付网关的 URL 放在这里
关于angular - 在 Angular 组件内接收 POST 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53926233/