18887-18887/com.doumi.bclient E/DefaultWebViewClient: webview error !!!!errorCode=-5,failingUrl=https://mapi.alipay.com/gateway.do?_input_charset=utf-8&it_b_pay=1d¬ify_url=http://pay.jz.ganji.com/pay/notify/alipay.php&out_trade_no=2016031800029972&partner=2088121187952426&payment_type=1&return_url=http://m.vip.doumi.com/bwap/return/?rp=mobile&aPPType=client&uid=470715&charge_no=20160318145829289732347&seller_id=2088121187952426&service=alipay.wap.create.direct.pay.by.user&subject=%E5%95%86%E6%88%B7%E5%85%85%E5%80%BC&total_fee=0.01&sign=6673afba777e8cf4860e7b9326616c20&sign_type=md5,description=net::ERR_PROXY_CONNECTION_FAILED分析:
step1: 在4.4以下的版本不出错,4.4以上的版本才出错step2: 抓包,得到服务器端传回的链接,经测试能正常打开(如下):https://mapi.alipay.com/gateway.do?_input_charset=utf-8&it_b_pay=1d¬ify_url=http%3A%2F%2Fpay.jz-test.ganji.com%2Fpay%2Fnotify%2Falipay.php&out_trade_no=2016031800001416&partner=2088121187952426&payment_type=1&return_url=http%3A%2F%2Fm.vip.doumi.com%2Fbwap%2Freturn%2F%3Frp%3Dmobile%26apptype%3Dclient%26uid%3D117401%26charge_no%3D2016031814582987451524&seller_id=2088121187952426&service=alipay.wap.create.direct.pay.by.user&subject=%E5%95%86%E6%88%B7%E5%85%85%E5%80%BC&total_fee=10&sign=1f25c2ce1e53a952301b8ccaf60bae0f&sign_type=MD5step3:跟h5联合调试,h5收到url以后就进行urlencode,传回给native。(urlencode之后的链接如下)https%3a%2f%2fmapi.alipay.com%2fgateway.do%3f_input_charset%3dutf-8%26it_b_pay%3d1d%26notify_url%3dhttp%253A%252F%252Fpay.jz-test.ganji.com%252Fpay%252Fnotify%252Falipay.php%26out_trade_no%3d2016031800001416%26partner%3d2088121187952426%26payment_type%3d1%26return_url%3dhttp%253A%252F%252Fm.vip.doumi.com%252Fbwap%252Freturn%252F%253Frp%253Dmobile%2526apptype%253Dclient%2526uid%253D117401%2526charge_no%253D2016031814582987451524%26seller_id%3d2088121187952426%26service%3dalipay.wap.create.direct.pay.by.user%26subject%3d%25E5%2595%2586%25E6%2588%25B7%25E5%2585%2585%25E5%2580%25BC%26total_fee%3d10%26sign%3d1f25c2ce1e53a952301b8ccaf60bae0f%26sign_type%3dMD5step4: native收到h5的链接以后进行urldecode( urlDecode以后的代码如下),然后再从webview的loadUrlExt打开https://mapi.alipay.com/gateway.do?_input_charset=utf-8&it_b_pay=1d¬ify_url=http%3A%2F%2Fpay.jz-test.ganji.com%2Fpay%2Fnotify%2Falipay.php&out_trade_no=2016031800001416&partner=2088121187952426&payment_type=1&return_url=http%3A%2F%2Fm.vip.doumi.com%2Fbwap%2Freturn%2F%3Frp%3Dmobile%26apptype%3Dclient%26uid%3D117401%26charge_no%3D2016031814582987451524&seller_id=2088121187952426&service=alipay.wap.create.direct.pay.by.user&subject=%E5%95%86%E6%88%B7%E5%85%85%E5%80%BC&total_fee=10&sign=1f25c2ce1e53a952301b8ccaf60bae0f&sign_type=MD5截止到这一步为止,urldecode以后的url都能在浏览器里打开。。仔细对比报错信息里的failingUrl和当前decode以后的url发现,failingUrl是decode以后再进行了一次decode得到的,这是为什么呢。。。复习知识点:
Android4.4的发布,Android WebView改成由Chromium驱动了。之前是用webkit。Android4.4 webview有一个专门用于异步调用javaScript方法,evaluateJavascript() 。root cause:
android4.4以及以上的webview都需要用evaluateJavascript() 调用javascript的方法。用loadUrl会自动进行一次urldecode,再将结果传递给javascript。为了规避这一问题,需要采用以下逻辑:if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { aWebView.evaluateJavascript(aJS, null); } catch (Exception e) { aWebView.loadUrlExt("javascript:" + aJS); } } else { aWebView.loadUrlExt("javascript:" + aJS); }参考资料:
Android 4.4 中 WebView使用注意事项 http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1106/1920.htmlAndroid 4.4 WebView实现分析 http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1106/1921.htmlAndroid JSBridge的原理与实现 http://blog.csdn.net/dj0379/article/details/50766238
新闻热点
疑难解答