我正在尝试集成银行的支付网关集成。但是WKWebView
不会加载URL。
我要在WKWebView
中加载的URL是
这里是URL: http://www.mpenagarpalika.gov.in/EasyPay20/EncDataPage.jsp?copr_id=3163&requestId=XXXX&customerRefNo=XXXX&amount=3937.000&version=1.0&type=PRD¤cy=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 =%23%20 %%%%% 20%20%जव&bankReferenceNumber = W10000011447&fromSenderIP = 99.199.255.199
当我尝试在笔记本电脑浏览器上运行相同的URL时,它工作正常。
我尝试了以下选项:
let hiturl = paymentPageURL.addingPercentEncoding(withAllowedCharacters: CharacterSet(charactersIn: "!*'();:@&=+$,/?%#[]{} ").inverted)
let hiturl = paymentPageURL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
有人可以帮助我解决问题吗?我在做什么错了?
答案 0 :(得分:0)
好吧,我刚刚为您带来了经过测试的解决方案。请尝试以下代码...
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¤cy=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)
}
***还有一件重要的事情,请不要忘记在info.plist中添加以下行以进行延迟加载,否则WKWebView无法加载url。
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
答案 1 :(得分:-2)
我自己解决了这个问题。
解决方案是。 url中所有使用不同语言的字符都应使用base64编码。
谢谢