繁体   English   中英

Https 403 Flutter 中的禁止错误 Dart ZDB974238714CA8A3DE634A7FASTCE1D0 集成

[英]Https 403 Forbidden Error In Flutter Dart API Integration PayFAST

我正在尝试将 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);

您尝试发送请求的 API 是否有效? 正在发送的有效负载很可能是无效的,因此 4XX 错误 - 这通常是由未经身份验证的请求引起的。 如果请求有效,您可以尝试将 http 请求作为表单数据发送:

sendRequest() async {
  final uri = 'https://sandbox.payfast.co.za/onsite/process';

  http.Response response = await http.post(
      uri, body: {
    'merchant_id':'10022814',
    'merchant_key':'aemfu0aapxale',
    'amount':'100.00',
    'item_name':'#000001'
  });

  debugPrint(response.body);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM