问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/19720059/how-to-modify-the-value-of-the-key-x-requested-with-in-the-request-headers-of