Android Volley,重复的 Set-Cookie 被覆盖 [英] Android Volley, duplicate Set-Cookie is overridden

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

问题描述

尝试使用 Volley lib 作为我的 android 应用程序的网络包装器.我有一个连接已启动并正在运行,但问题是每次响应中有多个Set-Cookie"标头时 Volley 使用不能有重复键的 Map,并且只会存储最后一个 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 every time there is multiple "Set-Cookie" headers in the response Volley uses Map that cannot have duplicate keys, and will only store the last Set-cookie header and overwrite the rest.

这个问题有解决办法吗?

Is there a workaround for this issue?

还有其他库可以使用吗?

Is there another lib to use?

推荐答案

我尝试覆盖类来解决这个问题,但是当我不得不编辑 NetworkResponse,我在兔子洞里下降得太远了.所以我决定直接编辑 Volley 来获取数组中的所有响应头,而不是 Map.

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.

我的 fork 在 GitHub 上,我包含了一个 示例使用活动.

My fork is on GitHub and I included an example usage activity.

我对 NetworkResponse.java、BasicNetwork.java 和 HurlStack.java 进行了更改,详见 此提交.

I made changes to NetworkResponse.java, BasicNetwork.java and HurlStack.java as detailed in this commit.

然后在你的实际应用中使用你做这样的事情

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 Volley,重复的 Set-Cookie 被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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