Android的凌空,重复的Set-Cookie被重写 [英] Android Volley, duplicate Set-Cookie is overriden
问题描述
试图使用排LIB作为网络包装我的Android应用程序。我有一个连接,启动和运行,但问题是,每次有多个设置Cookie头在respons凌空使用不能有dupilcate键地图,并且只存储最后的Set-Cookie头和覆盖休息。
Trying to use Volley lib as a network wrapper for my android application. I have a connection up and running, but the problem is that everytime there is multiple "Set-Cookie" headers in the respons Volley uses Map that cannot have dupilcate keys, and will only store the last Set-cookie header and overwrite the rest.
是否有解决此问题?
难道还有其他的lib使用?
Is there another lib to use?
推荐答案
我试过overiding类来解决这个问题,但是,当我不得不修改<一个href="https://android.googlesource.com/platform/frameworks/volley/+/master/src/com/android/volley/NetworkResponse.java">NetworkResponse,我被降得远了rabbithole。所以,我决定只编辑直接凌空抢数组中的所有响应标头,而不是一个地图。
I tried overiding classes to fix this but when I had to edit NetworkResponse, I was descending too far down the rabbithole. So I decided to just edit Volley directly to grab all response headers in an array and not a Map.
我的叉子是 GitHub上我包含在一个<一个href="https://github.com/georgiecasey/android-volley-duplicateheadersfix/blob/master/src/com/georgiecasey/DuplicateHeadersFixExample.java">example使用活动。
My fork is on GitHub and I included an example usage activity.
我在<详细进行了更改,NetworkResponse.java,BasicNetwork.java和HurlStack.java href="https://github.com/georgiecasey/android-volley-duplicateheadersfix/commit/9f3cf1cf5684ce788c2bfae260a8e0ebe6fa93ac">this提交。
然后在实际的应用程序,你做这样的事用
Then to use in your actual apps you do something like this
protected Response<String> parseNetworkResponse(NetworkResponse response) {
// we must override this to get headers. and with the fix, we should get all headers including duplicate names
// in an array of apache headers called apacheHeaders. everything else about volley is the same
for (int i = 0; i < response.apacheHeaders.length; i++) {
String key = response.apacheHeaders[i].getName();
String value = response.apacheHeaders[i].getValue();
Log.d("VOLLEY_HEADERFIX",key + " - " +value);
}
return super.parseNetworkResponse(response);
}
这是一个肮脏的小技巧,但似乎目前的工作很适合我。
It's a dirty little hack but seems to work well for me at the moment.
这篇关于Android的凌空,重复的Set-Cookie被重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!