最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【暂未解决】Eclipse中调试Java代码期间如何修改值

Eclipse crifan 4759浏览 0评论

【背景】

折腾:

【教程】模拟登陆百度之Java代码版

期间,调试代码期间,发现,对应的第三次的访问百度,访问:

https://passport.baidu.com/v2/api/?login

时之前的cookie,是这样的:

[
    [version: 0][name: BAIDUID][value: 7164BE33080CE050940980ECBDFBCB9C:FG=1][domain: .baidu.com][path: /][expiry: Thu Sep 17 14:22:08 CST 2043],
    [version: 0][name: BDSVRTM][value: 1][domain: www.baidu.com][path: /][expiry: null],
    [version: 0][name: HOSUPPORT][value: 1][domain: passport.baidu.com][path: /][expiry: Sat Dec 04 14:22:31 CST 2021],
    [version: 0][name: H_PS_PSSID][value: 3359_3341_2776_1424_2981][domain: .baidu.com][path: /][expiry: null]
]

想要将其中的

H_PS_PSSID

expiry

的值,从null改为:

Thu Sep 17 14:22:08 CST 2043

保证其不过期。

但是在Eclipse中,发现无法更改:

current cookie H_PS_PSSID expiry is null want change

【解决过程】

1.参考:

Eclipse Tip: Change variable values while debugging

好像比如把要修改值的变量,加到Watch列表里面去。

2.所以去试试,

right click variable choose watch

然后去修改值:

Change Value

for current cookie change value for expiry date

填入新的值:

Thu Sep 17 14:22:08 CST 2043

然后OK:

set new expiry date value then ok

结果无法修改,cookieExpiryDate还是之前的null。

3.然后再去试试,找找另外别的cookie的expiry的值是什么,然后再参考去修改。

refer other cookie expiry date fastTime value copy

然后再去填入

H_PS_PSSID

的expiry的新值:

change H_PS_PSSID cookie expiry to new copied out value

结果却是超过int限制:

the literal of type int is out of range

4.参考:

Changing variables in realtime when debugging in eclipse?

提到的:

Change Variable Value

去试试表达式:

new Date("Thu Sep 17 14:22:08 CST 2043");

即:

set value again use new date input date string

看看是否有效。

结果都是错误:

error during the evaluation

5.然后想想,是不是少了return,所以去试试:

待会再试。

6.去把代码输入到Eclipse中:

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.搞定了如何用代码设置时间后,再去试试:

new GregorianCalendar(2043, 9, 17, 14, 22, 8);

即:

use new GregorianCalendar to set expiry value

结果是,还是不行。

8.再去试试上面的,加上return看看:

return new GregorianCalendar(2043, 9, 17, 14, 22, 8);

即:

use return new GregorianCalendar to set value again

结果是,还是不行。

 

【总结】

至此,还是没搞定,在Eclipse调试期间,如何去更改一个CookieStore中的一个cookie的cookieExpiryDate的值。

算了,还是另外,通过手动去写代码,去设置此Expiry值吧。

最后是用如下代码:

        	//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的值。

转载请注明:在路上 » 【暂未解决】Eclipse中调试Java代码期间如何修改值

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.178 seconds, using 22.11MB memory