title: How to set Cookies at Http Get method using Java
body: <p>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 completed the login, have read the response and extracted the cookies (3 pairs of (name,value) ). I then wrote the String containing the cookies like this:</p>
  
  <pre><code>CookieString="name1=value1; name2=value2; name3=value3"
  </code></pre>
  
  <p>I then do the following</p>
  
  <pre><code>HttpURLConnection connection
  connection = (HttpURLConnection)(new URL(Link).openConnection());
  connection.setRequestMethod("GET");
  connection.setRequestProperty("Connection", "Keep-Alive");
  connection.setRequestProperty("Cookie", CookieString );
  connection.connect();
  </code></pre>
  
  <p>I then read the page but it shows that I am not logged at the forum. What am I doing wrong?</p>
  
  <p>edit: I know that I must extract the security token if I want to make a post. My train of thought was that in order to extract it, I need to GET this particular page. But for the security token to be as a hidden field I must be online, thus I needed the cookies. But when I GET the page and I set the cookies as mentioned above i get the page as a guest, it shows that I am not online and the value of security token is guest which is not useful for me. I will check the link you gave  me and hopefully will find a solution.</p>