簡體   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