Problem simulating HTTP POST using HttpClient

醉酒当歌 提交于 2019-12-02 01:05:58

Visiting the link above and viewing the html source, it looks like the target path should be /en/s/planjourney/plan.

For everyone need an an answer to this post the solution is to use HttpContext to automatically manage cookies:

  HttpContext context=new BasicHttpContext();
  CookieStore cookiestore=new BasicCookieStore();
  context.setAttribute(ClientContext.COOKIE_STORE,cookiestore);

and pass it when you make an http request:

   HttpResponse response = client.execute(httpPost,context);

everytime you make a request your cookies store will automatically update! Easy!

Try using the HTTP Client 4.1 and set a redirect strategy on the HTTP Client for handling 302 status code (Moved Temporarily)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!