Fredefl
Fredefl

Reputation: 1381

Android WebView won't load CORS content in Gingerbread and below

I've set up a basic WebView in Android, and has pointed it to a url on my root domain (eg. https://example.com). I want to connect to a sockjs server at another port, but on the same domain (eg. https://example.com:81).

Now, it works like a charm in the default Android browser - but not in a WebView. The WebView loads my (CORS) Ajax request in Android 4.0, however in fx. Gingerbread and Froyo it doesn't.

Sockjs sets the header: Access-Control-Allow-Origin:https://example.com

Thanks!

UPDATE: I have found out that everything is fine without https...

Upvotes: 0

Views: 3700

Answers (1)

Fredefl
Fredefl

Reputation: 1381

Okay, I found out that my CA, Startcom SSL Authority, was not trusted by Android, and since my page was in a WebView, I didn't see the warning message. I inserted this code to make it "trust" my certificate:

mainWebView.setWebViewClient(new WebViewClient() {
    public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed() ;
    }
});

Hope this helps anyone out there who has the same problem.

Upvotes: 2

Related Questions