我正在尝试将 Payfast api 与我的应用程序集成。在 WebView 中,我可以正确地将请求的数据传递给给定的 https 地址,但是当它到达 https 请求端时会发生错误。只是我将相同的数据传递到相同的路径。有什么问题,非常感谢您的帮助。现在谢谢
当我按下提交按钮时,下面的代码会重定向正确的付款页面;
WebView(
initialUrl: new Uri.dataFromString(''' <!DOCTYPE html> <html>
<style>
input[type=button], input[type=submit], input[type=reset] {
background-color: #FF0000;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 8px 4px;
cursor: pointer;
}
</style>
<body style="background-color:#ffffff;">
<form action="https://sandbox.payfast.co.za/eng/process" method="post">
<input type="hidden" name="merchant_id" value="10022814">
<input type="hidden" name="merchant_key" value="aemfu0aapxale">
<input type="hidden" name="amount" value="$miktar">
<input type="hidden" name="item_name" value="Test Product">
<input type="submit" value="PAY NOW">
</form>
</body>
</html>
''',
mimeType: 'text/html').toString(),
javascriptMode: JavascriptMode.unrestricted,
gestureNavigationEnabled: true,
),
但是 http 请求时会出现 403 错误。
HttpClient httpClient = new HttpClient();
HttpClientRequest request = await httpClient.postUrl(Uri.parse( "https://sandbox.payfast.co.za/onsite/process"));
request.headers.set('accept' , 'application/json');
request.headers.set('merchant-id' , '10022814');
request.headers.set('merchant_key' , 'aemfu0aapxale');
//sbtu01@payfast.co.za
//headers
//request.headers.set('Accept' , 'application/json');
Map body = { 'merchant_id' : '10022814',
'merchant_key' : 'aemfu0aapxale',
'amount' : '100.00',
'item_name' : '#000001'} ;
//body
request.add(utf8.encode(json.encode(body)));
//response cevap
HttpClientResponse response = await request.close();
print(response.statusCode); // baglanti yapildi mi yapilmadi mi 200 ise yapildi
String reply = await response.transform(utf8.decoder).join();
httpClient.close();
print("payfast ici odeme");
print(reply);