Android的凌空,重复的Set-Cookie被重写 [英] Android Volley, duplicate Set-Cookie is overriden

查看:1845
本文介绍了Android的凌空,重复的Set-Cookie被重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图使用排LIB作为网络包装我的Andr​​oid应用程序。我有一个连接,启动和运行,但问题是,每次有多个设置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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆