【发布时间】:2018-09-14 14:45:14
【问题描述】:
我正在集成支付网关,发送数据的唯一方法是 http 发布请求。所以我问是否有可能使用角度 4 将数据发送到这个外部 api ?
我使用了这种形式:
<form [formGroup] = "form" (ngSubmit) = "redirect(form.value)">
<input type="text" name="card_number"
formControlName="card_number" >
<input type="text" name="expiry_date" formControlName="expiry_date">
<input type="text"
name="card_security_code"formControlName="card_security_code" >
<input type="submit" value="" id="submit2" name="submit">
</form>
这是我的功能:
this.form =new FormGroup ({
card_number: new FormControl(),
expiry_date: new FormControl(),
card_security_code: new FormControl()});
redirect= function (form) {
var body = "card_number=" + form.card_number+ "&expiry_date=" + form.expiry_date"&card_security_code=" +form.card_security_code;
this.http.post("https://sbcheckout.payfort.com/FortAPI/paymentPage", body).subscribe((data) => {});
}
我在 ionic 3 中尝试过这种形式,但我得到了这个 CORS 错误,请你们给点建议吗?
Failed to load https://sbcheckout.payfort.com/FortAPI/paymentPage: Redirect
from 'https://sbcheckout.payfort.com/FortAPI/paymentPage' to
'https://sbcheckout.payfort.com/FortAPI/paymentPageC?
S=1&token=NAX906AB61K8IMC40AKWEKOVLJDN6D&' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested
resource.
Origin 'http://localhost:8100' is therefore not allowed access.
【问题讨论】:
-
CORS 通常由服务器管理。我会联系 Payfort 并询问他们如何建议与他们进行集成以避免 CORS 问题。
-
如何使用角度发送数据,可以吗?
-
不确定“使用角度”是什么意思 - 但您已经通过此调用发送它:this.http.post("sbcheckout.payfort.com/FortAPI/paymentPage", body).subscribe((data) = > {}); } 使用 Angular 的 http 模块
-
嗯,响应被重定向到一个新页面,这不是一个简单的数据返回,我将请求发送到这个 url:sbcheckout.payfort.com/FortAPI/paymentPage,响应 url 是:webhook.site/a63b699a-5ce4-4990-a259-db34d8222829
标签: javascript html cors ionic3 angular2-forms