代码是HttpClient或servlet API来解析Cookie头
Apache HttpClient 或 servlet API 中是否有任何现有代码可以解析 Cookie 标头并从包含“name1=value1; name2=value2; ...”的字符串中获取 Cookie 列表? 编写代码来解析它似乎并不太难,但如果已经有一些现有代码,我想使用它。
Is there any existing code in Apache HttpClient or in the servlet API to parse Cookie header and obtain from a string that contains "name1=value1; name2=value2; ..." a list of Cookie? Writing code to parse this doesn't seem too hard, but if there is already some existing code, I'd like to use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您调用 getCookies() 在
HttpServletRequest
对象上,它将返回一个Cookie
对象数组。 如果您需要经常按名称查找 cookie,那么将它们放入 Map 中可能会更容易,这样就可以轻松查找它们(而不是每次都迭代数组)。 像这样的事情:如果您使用 HttpClient 而不是 servlet,则可以使用以下方法获取
Cookie
数组:其中 client 是您的 HttpClient 对象。
If you call getCookies() on the
HttpServletRequest
object, it will return an array ofCookie
objects. If you need to frequently look up cookies by name, then it may be easier to put them in to a Map so it's easy to look them up (rather than iterate over the Array each time). Something like this:If you're using HttpClient and not servlets, you can get the
Cookie
array using:where client is your HttpClient object.