State tentando di modificare la stringa User-Agent nella richiesta HTTP di un'app Android. Ho testato questo insieme con wireshark e l'emulatore, e ho visto che sebbene io abbia impostato la stringa useragent nella webview, la richiesta loadUrl associata non usa questa stringa user-agent. Invece vedo la stringa useragent di Dalvik nell'acquisizione di wireshark. Ecco il codice astratto. Qualche idea? O l'emulatore non supporta questo?setUserAgentString in Webview Android non ha alcun effetto sull'intestazione HTTP utilizzata in loadURL()
@Override
public void run() {
assert(context != null);
...
...
webView = new WebView(context);
...
String defaultUserAgent = "betaUAteststring";
// Clear per-application caches etc
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setAppCacheEnabled(false);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
....
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
..
}
@Override
public void onLoadResource(WebView view, String url) {
...
}
});
// Start loading
webView.getSettings().setUserAgentString(defaultUserAgent);
String setUA = webView.getSettings().getUserAgentString();
//--> logging here shows the correct user agent, so the webview does accept the value
// However the following statement does not result in an http request with the webviews user agent
webView.loadUrl(url);
//Alternative doesn't help either (and shouldn't according to javadoc)
//Map<String,String> headerMap = new HashMap<String,String>();
//headerMap.put("User-Agent","uaTestInAMap");
//webView.loadUrl(url, headerMap);
}
credo lo sto facendo nella riga "webView.setWebViewClient (new WebViewClient() ....." – damcify