2

Iam trying to open one website url on the webview.But iam getting Error "403 forbidden access is denied".How fix this issue? Iam using the wifi connection and i also written internet permission in the manifest file. Like this How to solve this issue? Thanks for any help.

joe
  • 221
  • 2
  • 5
  • 13

2 Answers2

1

For anyone having the same issue in 2018. Try the below code and read my explanation.

There are few possible reasons about why you can get the 403 Forbidden error. I have identified 2 of them.

  1. It is an SSL issue.
  2. Your User Agent is blocked by the website.

Here is how you set the SSL configurations. Here the newsWebView is a WebView.

newsWebView.setWebViewClient(new WebViewClient() {
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }

                public void onPageFinished(WebView view, String url) {
                }

                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                }

                public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) {
                    // TODO Auto-generated method stub
                    super.onReceivedSslError(view, handler, error);
                    handler.proceed();
                }
            });

This is how you set the User Agent. I am setting the Google Chrome agent, the one we normally find in our phones.

newsWebView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; <Android Version>; <Build Tag etc.>) AppleWebKit/<WebKit Rev> (KHTML, like Gecko) Chrome/<Chrome Rev> Mobile Safari/<WebKit Rev>");
PeakGen
  • 21,894
  • 86
  • 261
  • 463
-1

Try Adding this code on your Web Client:

 public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) {
                // TODO Auto-generated method stub
                super.onReceivedSslError(view, handler, error);
                handler.proceed();
            }

It will allow webview to load the page , in case of SSL error with website

Nargis
  • 4,687
  • 1
  • 28
  • 45