Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

wordpress - How can I force Java's HttpClient to accept invalid cookies?

I'm working on a script that logs into WordPress, however, HttpClient's cookie policy identifies the cookies set by WordPress to be invalid:

May 17, 2009 12:07:43 PM org.apache.commons.httpclient.HttpMethodBase processCookieHeaders
WARNING: Cookie rejected: "$Version=0; wordpress_dce2080bc042b2e639e4f5b3b704aa43=admin%7C1243786064%7C4c56aef46b1210d3d43d8b829fdf4d9a; $Path=/wp-content/plugins". Illegal path attribute "/wp-content/plugins". Path of origin: "/wp-login.php"
May 17, 2009 12:07:43 PM org.apache.commons.httpclient.HttpMethodBase processCookieHeaders
WARNING: Cookie rejected: "$Version=0; wordpress_dce2080bc042b2e639e4f5b3b704aa43=admin%7C1243786064%7C4c56aef46b1210d3d43d8b829fdf4d9a; $Path=/wp-admin". Illegal path attribute "/wp-admin". Path of origin: "/wp-login.php"

Without cookie support, the script can't login. How can I get around this?

(Using HttpClient 3.1)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check this post for further hints: Java HtmlUnit - can't login to wordpress

In similar situations I was able to use the following code (although I admit it doesn't work in the specific wordpress case):

HttpClient client = new HttpClient();
client.getParams().setParameter("http.protocol.single-cookie-header", true);
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...