Android WebView blocks redirect from https to http

前端 未结 4 2057
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 19:30

I have a solution where my Android WebView needs to first open a https url, then it will be redirected to a http url (it might be trying a http POST from the https site). Th

4条回答
  •  北海茫月
    2020-12-28 20:04

    There was a change in default WebView settings for mixed http/https content in Lollipop (API 20). See https://datatheorem.github.io/android/2014/12/20/webviews-andorid-lollipop/ for more details.

    To allow https to redirect to http you need to set the mixed content mode to MIXED_CONTENT_ALWAYS_ALLOW

     if (Build.VERSION.SDK_INT >= 21) {
            webview.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
        }
    

    Note that setting MIXED_CONTENT_ALWAYS_ALLOW is bad from security point of view, and as you note in your answer, it is better to support https on both sites.

    But for those that don't have control over the sites, this should work.

提交回复
热议问题