如何修改键“X-要求,以”在资源请求的web视图Android的请求头的价值,而不是网页的请求? [英] 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?
问题描述
我遇见了,当我捕捉到HTTP包时,我的web视图访问一个网址的问题。包装显示,通过发送AJAX请求有一个X-要求,与关键在头,其中有像com.xxx我的应用程序包名的值。我不希望我的URL访问知道请求来自于我的应用程序,所以我需要更换键X-要求,以'到另一个value.but我试过SLOUTION在<一个href="http://stackoverflow.com/questions/7610790/add-custom-headers-to-webview-resource-requests-android">Add自定义标头的WebView资源请求 - 机器人,所有的人都没有工作
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网址,地图&LT;字符串,字符串&GT; extraHeaders)。
将被称为只有在页面请求,而不是发送阿贾克斯的资源请求 shouldOverrideUrlLoading(web视图查看,字符串URL)
和 WebViewClient.shouldInterceptRequest(android.webkit.WebView观点,java.lang.String中的URL)
会调用每一个要求,但我不能修改标题在其中。
所以,这个问题的任何解决方案?太谢谢你了。
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.
推荐答案
好了,我终于解决了这个问题。我找不出来修改在加载页面仍然通过发送AJAX请求的报头的方式,但我还是选择了覆盖公共字符串getPackageName()
在应用程序
。我查查callingstack,如果调用来自android.webkit,我回到了我的包名称另一个字符串代替。所以,我的问题解决了。但根本问题还是离开了。
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.
这篇关于如何修改键“X-要求,以”在资源请求的web视图Android的请求头的价值,而不是网页的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!