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

后端 未结 6 1009
南方客
南方客 2020-12-15 14:25

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 1         


        
相关标签:
6条回答
  • 2020-12-15 15:07

    Take a look at this page, HttpClient Cookie Guide, and see if adjusting the cookie policy fixes your problem.

    EDIT:

    More specifically, try the Netscape Draft policy and see if its relaxed restrictions work with the WordPress cookies.

    0 讨论(0)
  • 2020-12-15 15:11

    HttpClient is the only thing in the world that respects the RFC. I put in a request to strike the whole prefix path to begin with. There are lots of sites that set the path to a path they then forward you to. It is a very useful thing to do. Since Chrome, IE, Firefox, Safari, Opera and every other browser doesn't care I think HTTPClient should stop caring so we can move on with our lives.

    0 讨论(0)
  • 2020-12-15 15:11

    You can implement your own cookie policy.
    See chapter 3.6 in this HTTPClient guide.

    0 讨论(0)
  • 2020-12-15 15:14

    In my opinion,you can download the source code of the httpclient, find the location of the log.warn ... , can delete them. I did so.

    0 讨论(0)
  • 2020-12-15 15:16

    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);
    
    0 讨论(0)
  • 2020-12-15 15:17

    Can you register your own Cookie Policy that is more relaxed?

    0 讨论(0)
提交回复
热议问题