简体   繁体   English

如何将 cookie 值作为字符串而不是 Map 传递<string, string>在 JSOUP 中?</string,>

[英]How to pass cookie value as string instead of Map<String, String> in JSOUP?

I wish to pass cookie value found in developer console as string programmatically using Jsoup .我希望使用Jsoup以编程方式将在开发人员控制台中找到的 cookie 值作为字符串传递。

I know below way to pass cookie in JSOUP我知道以下在 JSOUP 中传递 cookie 的方法

.cookies(login.cookies())

the value type is Map<String, String> var1值类型是Map<String, String> var1

But I wish to string as below, how to achieve it?但我希望字符串如下,如何实现呢?

 -H 'Cookie: currency=INR; magnitude=LC; ad=3d468...' \
        -H 'Referer: https://www.valueresearchonline.com/funds/26123/motilal-oswal-flexi-cap-fund-regular-plan/' \

在此处输入图像描述

I guess, you can write your own method to convert from Map<String, String> to String by using StringBuilder.我想,您可以编写自己的方法,使用 StringBuilder 将 Map<String, String> 转换为 String。

As you can see on your screenshot, cookies string is sent as a header named Cookie .正如您在屏幕截图中看到的那样, cookies 字符串作为名为Cookie的 header 发送。
If you already have the correct value you can set this header directly:如果你已经有了正确的值,你可以直接设置这个 header:

.header("Cookie", "currency=INR; magnitude=LC; ad=3d4686659c9...")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM