How to set Cookies at Http Get method using Java

前端 未结 3 1574
青春惊慌失措
青春惊慌失措 2020-12-01 16:09

I want to do a manual GET with cookies in order to download and parse a web page. I need to extract the security token, in order to make a post at the forum. I have complete

3条回答
  •  青春惊慌失措
    2020-12-01 17:01

    Assuming the cookie values are not hard-coded but obtained from a previous request, it's probably easiest to use the CookieHandler class.

    CookieHandler.setDefault(new CookieManager());
    

    Then your HttpURLConnection will automatically save any cookies it receives and send them back with the next request to the same host.

提交回复
热议问题