Java http cookie(Java http cookie)
如何从java中的URL获取cookie内容?
例如:当我访问google.com时使用LiveHttpHeaders我可以看到cookie返回如下。
饼干:SID =
DQAAAKEAAADA1VJiGC-O-Ml8cPfRIA8NxJ3rCQfXbRnh5NMw-l8eunfAKJNypj9Rss1_Ok2yyQXCU9qu4jM2TuASy2EE0KUknUOsdOgMz3W7WCDgey6OSZ-xi_ozh_lZP8paJ_OViG_G2FaTWciTyd4Mp_V0LYjgov1u6KkhATu8day8-nEckMXb4I56cse8SaiYFCjDmpUDmL6CDFij8Nxd3XDUEOTn5SCifKrRDohW6mAAaqzFPA; HSID=AvoV_TPUEmoSB6KMm; PREF=ID=260f8c0212fee1a7:U=6ca9509bc747fb21:TM=1297164689:LM=1297164690:S=opeCe3s85Xhm3Bq1; NID=43=EZNhkfgLmXVNQriZ2rjU0HGj6flDYy2nfsPD4Ef6pME0wvXxc5_avP1R9fSea0py_-F9xY3SJ6DpMvLXRT_bU7FH97s8sOmx7l49cwvNUbYTwJcY0xqs-0vKqybTeNZY
DQAAAKEAAADA1VJiGC-O-Ml8cPfRIA8NxJ3rCQfXbRnh5NMw-l8eunfAKJNypj9Rss1_Ok2yyQXCU9qu4jM2TuASy2EE0KUknUOsdOgMz3W7WCDgey6OSZ-xi_ozh_lZP8paJ_OViG_G2FaTWciTyd4Mp_V0LYjgov1u6KkhATu8day8-nEckMXb4I56cse8SaiYFCjDmpUDmL6CDFij8Nxd3XDUEOTn5SCifKrRDohW6mAAaqzFPA; HSID=AvoV_TPUEmoSB6KMm; PREF=ID=260f8c0212fee1a7:U=6ca9509bc747fb21:TM=1297164689:LM=1297164690:S=opeCe3s85Xhm3Bq1; NID=43=EZNhkfgLmXVNQriZ2rjU0HGj6flDYy2nfsPD4Ef6pME0wvXxc5_avP1R9fSea0py_-F9xY3SJ6DpMvLXRT_bU7FH97s8sOmx7l49cwvNUbYTwJcY0xqs-0vKqybTeNZY
我如何获得SID的价值? 这些东西在UrlConnection类的
getHeaderFieldKey()
中不可用。 我试图获取默认的cookieHandler,但系统返回null。How can i get the cookie contents from a URL in java ?
Eg: Using LiveHttpHeaders when i visit google.com i can see cookie returned as follows.
Cookie: SID=
DQAAAKEAAADA1VJiGC-O-Ml8cPfRIA8NxJ3rCQfXbRnh5NMw-l8eunfAKJNypj9Rss1_Ok2yyQXCU9qu4jM2TuASy2EE0KUknUOsdOgMz3W7WCDgey6OSZ-xi_ozh_lZP8paJ_OViG_G2FaTWciTyd4Mp_V0LYjgov1u6KkhATu8day8-nEckMXb4I56cse8SaiYFCjDmpUDmL6CDFij8Nxd3XDUEOTn5SCifKrRDohW6mAAaqzFPA; HSID=AvoV_TPUEmoSB6KMm; PREF=ID=260f8c0212fee1a7:U=6ca9509bc747fb21:TM=1297164689:LM=1297164690:S=opeCe3s85Xhm3Bq1; NID=43=EZNhkfgLmXVNQriZ2rjU0HGj6flDYy2nfsPD4Ef6pME0wvXxc5_avP1R9fSea0py_-F9xY3SJ6DpMvLXRT_bU7FH97s8sOmx7l49cwvNUbYTwJcY0xqs-0vKqybTeNZY
How do i get the value of SID ? These things are not available in
getHeaderFieldKey()
of UrlConnection class. I tried to get the default cookieHandler but the system returns null.
原文:https://stackoverflow.com/questions/4932761
最满意答案
您可以使用反射访问实例的字段:
StudentRecord obj; Field field = obj.getClass().getField("firstName"); // or StudentRecord.class.getField() CobolString cs = (CobolString)field.get(obj); cs.setValue("John");
如果该字段是
private
,请在调用Field.get()
之前执行此操作:field.setAccessible(true);
You can access the fields of an instance using reflection:
StudentRecord obj; Field field = obj.getClass().getField("firstName"); // or StudentRecord.class.getField() CobolString cs = (CobolString)field.get(obj); cs.setValue("John");
If the field is
private
, execute this before callingField.get()
:field.setAccessible(true);
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
对象没有属性'get'(object has no attribute 'get')[2022-08-19]
你的问题在这里: intention = Intention.objects.get(pk=id) form = IntentionForm(intention) # An unbound form 表单的第一个参数是数据,但您传递的是实例。 要正确传递您应该使用的实例: intention = Intention.objects.get(pk=id) form = IntentionForm(instance=intention) # An unbound form Your problem is h ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你混淆了函数引用和函数调用的概念。 读取Leaflet标记事件在错误的时间触发 - 即使问题和设置不同,解决方案也是相同的。 You're confusing the concepts of function references and function calls. Read Leaflet marker event fires at wrong time - even if the question and setup is different, the solution is the same.
-
从一个对象数组中的一个对象访问父设备/ get方法(Access to a parent set/get method from one object inside an array of objects)[2024-01-18]
我想要的是b.array[0].aParentMethod返回ba , 你需要做两件事才能做到这一点: 将父对象引用传递给子对象 将吸气剂添加到使用父参考的孩子以获得a 例如,像这样的东西(见***评论): function parent() { this.a; this.array=[]; this.array.push(new child(this)); // *** } function child(parent) ... -
对象的方法“父”失败(Method 'Parent' of object failed)[2022-02-02]
您的代码看起来没有任何问题。 因此,从研究到目前为止,我找到了三种可能的解决方案: 确保表单名称中没有特殊字符 紧凑和维修 创建一个新的空白项目,并将所有数据库导入到空白项目中 There doesn't look like there is anything at all wrong with your code. So from research there seem to be three possible solutions that I have found so far: Make sure t ... -
C ++:父对象在没有方法调用的情况下更改其id属性(C++: Parent object change their id attribute without method call)[2022-04-05]
operator+重载中的这一行: _id.append("+").append(p._id), 你必须在这里非常小心,你当前在一个对象中(在你的例子中,这将是G对象)。 append实际上改变了本地字符串,所以你的代码附加+然后p._id然后深度复制到返回的值。 快速解决方法是将其更改为临时版,以满足您的需求: _id + "+" + p._id 为了避免将来出现这样的问题,你应该将操作符重载声明为友元方法,这样就可以非常清楚你在操作什么了。 friend Point operator+ (cons ... -
您可以使用反射访问实例的字段: StudentRecord obj; Field field = obj.getClass().getField("firstName"); // or StudentRecord.class.getField() CobolString cs = (CobolString)field.get(obj); cs.setValue("John"); 如果该字段是private ,请在调用Field.get()之前执行此操作: field.setAccessible(true) ...
-
重新启动模拟器后,foo()现在被调用,它只是没有正确设置背景......但这是另一个问题。 After restarting the emulator, foo() is now getting called, it just doesn't set the background properly...but that is another problem.
-
这里的问题与super或继承无关。 通过继承,父/子关系在类之间。 但在您的示例中, ChildClass不继承ParentClass ,因此不相关。 但是,在Qt中还存在另一种父/子关系,即实例之间。 窗口小部件的构造函数有一个参数,允许您传入对父对象(通常是另一个窗口小部件实例)的引用。 但是,参数是可选的,因此如果您没有显式设置它,之后调用parent()将只返回None 。 示例代码中的特定错误是,子项永远不会被赋予父项。 以下是您的示例应该是什么样子: class ParentClass(QtGu ...