在路上 > 工作和技术 > IDE TextEditor > Eclipse > 【暂未解决】Eclipse中调试Java代码期间如何修改值
【背景】
折腾:
期间,调试代码期间,发现,对应的第三次的访问百度,访问:
https://passport.baidu.com/v2/api/?login
时之前的cookie,是这样的:
[ |
想要将其中的
H_PS_PSSID
的
expiry
的值,从null改为:
Thu Sep 17 14:22:08 CST 2043
保证其不过期。
但是在Eclipse中,发现无法更改:
【解决过程】
1.参考:
Eclipse Tip: Change variable values while debugging
好像比如把要修改值的变量,加到Watch列表里面去。
2.所以去试试,
然后去修改值:
Change Value
填入新的值:
Thu Sep 17 14:22:08 CST 2043 |
然后OK:
结果无法修改,cookieExpiryDate还是之前的null。
3.然后再去试试,找找另外别的cookie的expiry的值是什么,然后再参考去修改。
然后再去填入
H_PS_PSSID
的expiry的新值:
结果却是超过int限制:
4.参考:
Changing variables in realtime when debugging in eclipse?
提到的:
去试试表达式:
1
|
new
Date(
"Thu Sep 17 14:22:08 CST 2043"
);
|
即:
看看是否有效。
结果都是错误:
5.然后想想,是不是少了return,所以去试试:
待会再试。
6.去把代码输入到Eclipse中:
1
|
Date newExpiryDate =
new
Date(
"Thu Sep 17 14:22:08 CST 2043"
);
|
结果显示:
The constructor Date(String) is deprecated |
详见:
【已解决】Eclipse中用java代码去new Date结果出错:The constructor Date(String) is deprecated
7.搞定了如何用代码设置时间后,再去试试:
1
|
new
GregorianCalendar(
2043
,
9
,
17
,
14
,
22
,
8
);
|
即:
结果是,还是不行。
8.再去试试上面的,加上return看看:
1
|
return
new
GregorianCalendar(
2043
,
9
,
17
,
14
,
22
,
8
);
|
即:
结果是,还是不行。
【总结】
至此,还是没搞定,在Eclipse调试期间,如何去更改一个CookieStore中的一个cookie的cookieExpiryDate的值。
算了,还是另外,通过手动去写代码,去设置此Expiry值吧。
最后是用如下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
//do some workaround to makesure here cookie H_PS_PSSID not expire
//[version: 0][name: H_PS_PSSID][value: 3359_3341_2776_1424_2981][domain: .baidu.com][path: /][expiry: null]
//Date newExpiryDate = new Date("Thu Sep 17 14:22:08 CST 2043");
//Date newExpiryDate = new Date();
Date newExpiryDate =
new
Date(
2043
,
9
,
17
);
//Calendar newExpiryCalendar = new Calendar();
//Calendar newExpiryCalendar = new GregorianCalendar();
//Calendar newExpiryCalendar = new GregorianCalendar(2043, 9, 17);
//Calendar newExpiryCalendar = new GregorianCalendar(2043, 9, 17, 14, 22, 8);
BasicClientCookie hPsPssidCookie =
null
;
int
hPsPssidCookieIdx =
0
;
curCookieList = crl.getCurCookieList();
for
(Cookie ck : curCookieList)
{
if
(ck.getName().equalsIgnoreCase(
"H_PS_PSSID"
))
{
hPsPssidCookieIdx = curCookieList.indexOf(ck);
hPsPssidCookie = (BasicClientCookie) ck;
hPsPssidCookie.setExpiryDate(newExpiryDate);
ck = hPsPssidCookie;
break
;
}
}
crl.setCurCookieList(curCookieList);
|
基本实现了,手动去修改那个特殊的cookie的expiry的值。