use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method combinesSameHeadersWithComma.
@Test
public void combinesSameHeadersWithComma() throws IOException {
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
String url = "http://direct.infohound.net/tools/q.pl";
Connection con = Jsoup.connect(url);
con.get();
assertEquals("text/html", con.response().header("Content-Type"));
assertEquals("no-cache, no-store", con.response().header("Cache-Control"));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method followsRelativeDotRedirect.
@Test
public void followsRelativeDotRedirect() throws IOException {
// redirects to "./ok.html", should resolve to http://direct.infohound.net/tools/ok.html
// to ./ok.html
Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-rel-dot.pl");
Document doc = con.post();
assertTrue(doc.title().contains("OK"));
assertEquals(doc.location(), "http://direct.infohound.net/tools/ok.html");
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method multiCookieSet.
@Test
public void multiCookieSet() throws IOException {
Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-cookie.pl");
Connection.Response res = con.execute();
// test cookies set by redirect:
Map<String, String> cookies = res.cookies();
assertEquals("asdfg123", cookies.get("token"));
assertEquals("jhy", cookies.get("uid"));
// send those cookies into the echo URL by map:
Document doc = Jsoup.connect(echoURL).cookies(cookies).get();
assertEquals("token=asdfg123; uid=jhy", ihVal("HTTP_COOKIE", doc));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method throwsExceptionOnError.
@Test
public void throwsExceptionOnError() {
String url = "http://direct.infohound.net/tools/404";
Connection con = Jsoup.connect(url);
boolean threw = false;
try {
Document doc = con.get();
} catch (HttpStatusException e) {
threw = true;
assertEquals("org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, URL=http://direct.infohound.net/tools/404", e.toString());
assertEquals(url, e.getUrl());
assertEquals(404, e.getStatusCode());
} catch (IOException e) {
}
assertTrue(threw);
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method followsNewTempRedirect.
@Test
public void followsNewTempRedirect() throws IOException {
// http://jsoup.org
Connection con = Jsoup.connect("http://direct.infohound.net/tools/307.pl");
Document doc = con.get();
assertTrue(doc.title().contains("jsoup"));
assertEquals("https://jsoup.org/", con.response().url().toString());
}
Aggregations