how to modify the value of the key 'X-requested-with' in the request headers of resource request in Android webview, but not a page request?

给你一囗甜甜゛ 提交于 2019-11-29 22:28:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!