Android Question WebView fails to load page with 403 error

Alessandro71

Well-Known Member
Licensed User
Longtime User
I have an URL with a strange behavior
it's getting loaded correctly in Chrome, but it gets a 403 error in a WebView
i suspect the web server is expecting some header for a proper browser request
i already tried setting a standard user-agent but with no different outcome
B4X:
            Dim m As Map
            m.Initialize
            m.Put("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; zh_CN) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0 baidubrowser/1.x Safari/534.7")
            Dim r As Reflector
            r.Target = WV_meteowidget
            r.RunMethod4("loadUrl", Array As Object(url, m), Array As String("java.lang.String", "java.util.Map"))
 

JohnC

Expert
Licensed User
Longtime User
Try this...

1) Add the chrome client to the webview as mentioned in my signature tip #1
2) Load the url into webview using it's regular .LoadURL method instead of using relfection:
B4X:
Wv.LoadURL = UrlToLoad

3) Yes, my above suggestion does not set the useragent, but first see if it works as is, if not then you can use the webviewsettings lib to set it:
B4X:
    Dim UA As String
    UA = useragentstring
    wvs.setUserAgentString(wv,UA)

*** Also, I noticed that you didn't set the "URL" variable to anything in the code you posted if that might be the cause of your error.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
1) Add the chrome client to the webview as mentioned in my signature tip #1

looks like the addWebChromeClient method is not available in the WebViewExtras2 library i'm using

2) Load the url into webview using it's regular .LoadURL method instead of using relfection:

yes, that was the first attempt, which didn't worked
the quoted code is after some attempts
and BTW, the "url" variable is correctly set before
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
looks like the addWebChromeClient method is not available in the WebViewExtras2 library i'm using

Well, that's your best bet to get this working, so I would download the version (1.42) from this page and see if adding the chrome client will work:

 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
well, it actually hasn't worked, because I still get the same 403 error, but using the WebViewExtras capability of extracting resulting HTML, I was able to intercept the error and open a full browser instead
thank you
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
This is a long shot (because normally you would have received a different error message if this was the cause), but try adding this line to your apps manifest:

B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)

Since the URL that you are trying to navigate to is NOT SSL (Just HTTP), this setting allows non-ssl connections.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
well, I'm out of ideas :confused:
 
Upvote 0
Top