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
// Grab Set-Cookie headers:
List cookies = connection.getHeaderFields().get("Set-Cookie");
// ...
// Send them back in subsequent requests:
for (String cookie : cookies) {
connection.addRequestProperty("Cookie", cookie.split(";", 1)[0]);
}
Above code will work for sending multiple cookies just use setRequestProperty instead of addRequestProperty. The working code is:
// Grab Set-Cookie headers:
List cookies = connection.getHeaderFields().get("Set-Cookie");
// ...
// Send them back in subsequent requests:
for (String cookie : cookies) {
connection.setRequestProperty("Cookie", cookie.split(";", 1)[0]);
}