Android Volley,重复的 Set-Cookie 被覆盖

Android Volley, duplicate Set-Cookie is overridden(Android Volley,重复的 Set-Cookie 被覆盖)
本文介绍了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 被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)