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

查看:730
本文介绍了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?

是否还有其他lib可供使用?

Is there another lib to use?

推荐答案

我尝试过覆盖类来解决这个问题,但是当我不得不编辑NetworkResponse ,我在rabbithole下降得太远了。所以我决定直接编辑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.

我的分叉在 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天全站免登陆