Android WebView 未加载 HTTPS URL
public void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
setContentView(R.layout.show_voucher);
webView=(WebView)findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
String url ="https://www.paymeon.com/Vouchers/?v=%C80%8D%B1x%D9%CFqh%FA%84%C35%0A%1F%CE&iv=%25%EE%BEi%F4%DAT%E1"
//webView.loadUrl(url); // Not Working... Showing blank
webView.loadUrl("http://www.yahoo.com"); // its working
}
当我尝试在 WebBView 中加载 URL 时,它只显示空白屏幕。如果我加载 Google.com 或 yahoo.com,它工作正常。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
请访问此链接:
将此重写方法添加到您的 WebViewClient 实现中。您需要使用 Android SDK 2.2(API 级别 8)或更高版本来编译它。该方法出现在 2.2(API 级别 8)的公共 SDK 中,但我们已经在运行 2.1、1.6 和 1.5 的设备上对其进行了测试,并且它也适用于这些设备(所以显然该行为一直存在)。
这会对你有帮助。
Please visit this link:
Add this overriding method to your WebViewClient implementation. You'll need to compile it with Android SDK 2.2 (API level 8) or later. The method appears in the public SDK as of 2.2 (API level 8) but we've tested it on devices running 2.1, 1.6 and 1.5 and it works on those devices too (so obviously the behaviour has been there all along).
this will help you.
根据到目前为止的正确答案,下面是一个可能有帮助的小代码示例。
首先,创建一个扩展 WebViewClient 的类,并将其设置为忽略 SSL 错误:
然后使用您的 Web 视图对象(在 OnCreate() 方法中启动)将其 Web 视图客户端设置为覆盖类的实例:
Per correct answer by fargth, follows is a small code sample that might help.
First, create a class that extends WebViewClient and which is set to ignore SSL errors:
Then with your web view object (initiated in the OnCreate() method), set its web view client to be an instance of the override class:
为了根据新的安全策略正确处理 SSL 证书验证并避免 Google 拒绝应用程序,请更改代码以在服务器提供的证书满足您的期望时调用 SslErrorHandler.proceed(),否则调用 SslErrorHandler.cancel()。
例如,我添加了一个警报对话框来让用户确认,并且 Google 似乎不再显示警告。
更改后,将不会显示警告。
To properly handle SSL certificate validation and avoid application rejection from Google according new Security Policy, Change your code to invoke SslErrorHandler.proceed() whenever the certificate presented by the server meets your expectations, and invoke SslErrorHandler.cancel() otherwise.
For example, I add an alert dialog to make user have confirmed and seems Google no longer shows warning.
After this changes it will not show warning.
覆盖 onReceivedSslError 并删除
并解决Google安全问题:
完整代码是:
override onReceivedSslError and remove
And to solve Google security:
Full code is:
删除下面的代码就可以了
Remove the below code it will work
复制并粘贴你的代码行,兄弟,它会起作用的,相信我:)我在想,你会得到一个 ssl 错误。如果您使用重写 onReceivedSslError 方法并删除 super 它的 super 方法。只需编写 handler.proceed() ,错误就会解决。
Copy and paste your code line bro , it will work trust me :) i am thinking ,you get a ssl error. İf you use override onReceivedSslError method and remove super it's super method. Just write handler.proceed() ,error will solve.
我遵循了上面的答案,但它似乎仍然不适合我,下面的代码在集成通常是 https 请求的支付网关时为我做了一个技巧:
上面的代码在 webview 中执行 post 请求并重定向到支付网关。
设置
settings.setDomStorageEnabled(true);
对我来说是一个技巧希望这有帮助。
I followed the answers above but still it seems not to be working for me below code did a trick for me when integrating payment gatways which are usually https requests :
Above code is doing a post request in webview and redirecting to payment gateway.
Setting
settings.setDomStorageEnabled(true);
did a trick for meHope this helps .
要处理 SSL url,方法 onReceivedSslError() 来自 WebViewClient 类,这是一个示例:
您可以查看我的完整示例 这里:
https://github.com/Jorgesys/Android-WebView-Logging
< /a>
To handle SSL urls the method onReceivedSslError() from the WebViewClient class, This is an example:
You can check my complete example here:
https://github.com/Jorgesys/Android-WebView-Logging
要解决 Google 安全问题,请执行以下操作:
到顶部的行:
代码:
To solve Google security, do this:
Lines to the top:
Code:
如果您想在 Google Play 商店之外使用 APK,例如,私有的解决方案可能会起作用,如下所示:
如果您想添加额外的可选安全层,您可以尝试使用 证书固定。恕我直言,这对于私人或内部使用来说没有必要。
如果您计划在 Google Play 商店上发布应用,那么您应该避免
@Override onReceivedSslError(...){...}。特别是使用 handler.proceed()。Google 会找到此代码片段,并肯定会拒绝您的应用程序,因为使用 handler.proceed() 的解决方案将抑制各种内置安全机制< /强>。
就我而言,SSL 证书链已损坏。您可以使用 SSL 检查器 或使用 SSLLabs。但请不要问我这是怎么发生的。我完全不知道。
不管怎样,重新安装 SSL 证书后,所有有关“WebView 中不受信任的 SSL 证书”的错误终于消失了。 我还删除了 onReceivedSslError(...) 的 @Override 并摆脱了 handler.proceed(),瞧我的应用程序没有被 Google Play 商店拒绝(再次)。
In case you want to use the APK outside the Google Play Store, e.g., private a solution like the following will probably work:
In case you want to add an additional optional layer of security, you can try to make use of certificate pinning. IMHO this is not necessary for private or internal usage tough.
If you plan to publish the app on the Google Play Store, then you should avoid
@Override onReceivedSslError(...){...}. Especially making use of handler.proceed(). Google will find this code snippet and will reject your app for sure since the solution with handler.proceed() will suppress all kinds of built-in security mechanisms.
In my case, the SSL certificate chain was broken. You can quickly test such issues with SSL Checker or more intermediate with SSLLabs. But please do not ask me how this can happen. I have absolutely no clue.
Anyway, after reinstalling the SSL certificate, all errors regarding the "untrusted SSL certificate in WebView whatsoever" disappeared finally. I also removed the @Override for onReceivedSslError(...) and got rid of handler.proceed(), and é voila my app was not rejected by Google Play Store (again).
推荐的方法是
1.不要调用 super 方法(从重写的方法中删除 super 调用)
2.Google 建议调用 SslErrorHandler.cancel()不提示对话框
暴露 SSL 错误
最好的解决方案是什么?
删除此覆盖方法
Recommended approach will be
1.Don't call super method(Remove super call from overridden method)
2.Google recommend to call SslErrorHandler.cancel() method if any error comes
3.Don't Prompt dialog to expose SSL errors
Whats the best solution??
Remove this override method
我的网站是一个在 Angular 8 上开发的子域,它也使用本地存储和 cookies。设置以下行以及上述其他解决方案后显示网站。
My website is a subdomain which is developed on angular 8 which is also using localstorage and cookies. website showed after setting the below line, along with other solutions mentioned above.
在清单中的应用程序标记中添加 android:usesCleartextTraffic="true" 一切都可以。这对我有用。
add android:usesCleartextTraffic="true" in application tag in manifest all will be ok . this works for me.
在 java 代码中使用此行 webview.getSettings().setDomStorageEnabled(true)
Use this line webview.getSettings().setDomStorageEnabled(true) in your java code
设置这两个属性足以让它为我工作,并且不会暴露安全问题:
Setting thoses two properties were enough to make it work for me, and doesn't expose to security issues :
检查您的用户代理,如果太长,您应该收到此错误
check your User Agent , if it too long your should get this error
看来 SSL 错误和 Google 安全性可以在 sketchware 和 Android studio 中使用下面的代码来解决此问题。
It seems SSL errors and Google security for solve this use below code in sketchware and Android studio.