4

I have met a problem when I capture the http package when my webView visit a url. the package shows that the request send by ajax has a 'X-requested-with' key in the headers, which has the value of my app package name like 'com.xxx'. I don't want the url I visited to know the request came from my app, so I need to replace the key 'X-requested-with' to another value.but I tried the sloution in Add custom headers to WebView resource requests - android, all of them do not work.

loadUrl(Strring url, Map<String, String> extraHeaders) will be called only in the page request, not in the resource request send by ajax.shouldOverrideUrlLoading(WebView view, String url) and WebViewClient.shouldInterceptRequest(android.webkit.WebView view, java.lang.String url) will be called in every request, but I can't modify headers in them. So any solutions to the question? Thank you so much.

Community
  • 1
  • 1
blank_ken
  • 119
  • 1
  • 5

1 Answers1

7

well, finally I solve the question. I can't find out the way to modify the headers in the request send by ajax in an loading page still, but I chose to override public String getPackageName() in Application. I look up the callingstack, if the calling comes from android.webkit, I return another string instead of my package name. So my issues solved. But the basic question still leaves.

blank_ken
  • 119
  • 1
  • 5
  • 1
    i followed your advice but the app force closes when i override that method. Even when i only change the return string if the calling comes from android.webkit. You didnt get an error when the webview is created? – Antilope Dec 28 '15 at 13:57