0

I am trying to integrate a payment gateway integration of a bank. But the WKWebView doesn't load the URL.

The URL which I am trying to load in WKWebView is

Here is URL: http://www.mpenagarpalika.gov.in/EasyPay20/EncDataPage.jsp?copr_id=3163&requestId=XXXX&customerRefNo=XXXX&amount=3937.000&version=1.0&type=PRD&currency=INR&returnURL=http%3a%2f%2fwww.mpenagarpalika.gov.in%2fwt_easypay1res%2fgetdecrypt&prePopulatedInfo=1000000001%7c0274%7cW10000011447%7cINR%7c3937.000&reserveField1=MN&reserveField2=WTax&reserveField3=Water_Tax&reserveField4=समीम&reserveField5=वार्ड%20क्र%2006%20%20जवाहरलाल&bankReferenceNumber=W10000011447&fromSenderIP=99.199.255.199

When I try to run the same URL on laptop browser then it's working fine.

I have tried these options:

let hiturl = paymentPageURL.addingPercentEncoding(withAllowedCharacters: CharacterSet(charactersIn: "!*'();:@&=+$,/?%#[]{} ").inverted)

let hiturl = paymentPageURL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)

What am I doing wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
Rachna
  • 213
  • 4
  • 17

2 Answers2

0

I just bring a tested solution for you. Please try below code:

let sampleURL = "http://www.mpenagarpalika.gov.in/EasyPay20/EncDataPage.jsp?copr_id=3163&requestId=XXXX&customerRefNo=XXXX&amount=3937.000&version=1.0&type=PRD&currency=INR&returnURL=http%3a%2f%2fwww.mpenagarpalika.gov.in%2fwt_easypay1res%2fgetdecrypt&prePopulatedInfo=1000000001%7c0274%7cW10000011447%7cINR%7c3937.000&reserveField1=MN&reserveField2=WTax&reserveField3=Water_Tax&reserveField4=समीम&reserveField5=वार्ड%20क्र%2006%20%20जवाहरलाल&bankReferenceNumber=W10000011447&fromSenderIP=99.199.255.199/"

if let encoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed),
            let myURL = URL(string: encoded)
        {
            print(myURL)
            let myRequest = URLRequest(url: myURL)
            myWebView.load(myRequest)
        }

And one more important thing, please don't forget to add below lines in info.plist for lazy loading, otherwise WKWebView can't able to load the url.

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>
halfer
  • 19,824
  • 17
  • 99
  • 186
emraz
  • 1,563
  • 20
  • 28
-2

The solution to this is: all the characters in url which are in different language should be base64 encoded.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rachna
  • 213
  • 4
  • 17
  • Not my vote but your answer would be a lot better if you showed the needed code to make this work. – rmaddy May 31 '19 at 06:31
  • base64 encoding might work for you but will it work for everyone? I mean easypay accepts base64 encoded content and decodes it. Again not my down vote. – Satheesh May 31 '19 at 06:39