Skip to content

Instantly share code, notes, and snippets.

@jhy
Created October 10, 2014 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhy/2be82da05b4b6be6dadd to your computer and use it in GitHub Desktop.
Save jhy/2be82da05b4b6be6dadd to your computer and use it in GitHub Desktop.
package io.jhy.scratch;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
/**
* http://stackoverflow.com/questions/26281903/jsoup-cookie-id-without-post/
*/
public class GetCookieDemo {
public static void main(String[] args) throws IOException {
String url = "http://direct.infohound.net/tools/set-cookie.pl";
Connection.Response res = Jsoup.connect(url).userAgent("Mozilla").execute();
String sessionId = res.cookie("sessionId");
Document doc = res.parse();
log("Session id from cookie: %s", sessionId);
}
static void log(String msg, Object... args) {
System.out.println(String.format(msg, args));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment