I'm using the loadUrl() method in an activity's onCreate() method to load content from an external web server into a webview (I'm building an adroid app).
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("http://server-name/path/to/my/server/app/");
}
On the server I check the ACCEPT HTTP header to decide which data format I will deliver to a client.
Now the problem is: the loadUrl() method seems to always send the ACCEPT header value "application/xml, ...", which will cause my server to deliver data not as nicely layouted html (this is what I want for the webview), but rather as pure xml (which is good for e.g. some web service client).
So what I want to do is to set the ACCEPT HTTP header to "text/html", but the loadUrl() method won't allow me to do that.
I checked out the source code for cordova/android and found, that the loadUrl() method (in CordovaWebView.java) finally calls the (android sdk) WebView's loadUrl() method, which is overloaded to take some additional http headers. But I can't access that loadUrl method through normal cordova use.
So I edited the CordovaWebView's loadUrlNow() method, which calls the WebView's loadUrl() method and hardcoded an extra header:
void loadUrlNow(String url) {
...
Map<String, String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("ACCEPT", "text/html");
super.loadUrl(url, extraHeaders);
}
then compiled it, replaced the original cordova.jar with my own and rebuild my android app. But if I now start the app and check the ACCEPT HTTP header on server side, the ACCEPT header didn't change. It's value is the very same than before hardcoding the extra header; it seems that I can't change that header.
So, is there any way to set the ACCEPT http header when calling the loadUrl() method?