use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method followsTempRedirect.
@Test
public void followsTempRedirect() throws IOException {
// http://jsoup.org
Connection con = Jsoup.connect("http://direct.infohound.net/tools/302.pl");
Document doc = con.get();
assertTrue(doc.title().contains("jsoup"));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method followsRedirectsWithWithespaces.
@Test
public void followsRedirectsWithWithespaces() throws IOException {
// to http://www.google.com/?q=white spaces
Connection con = Jsoup.connect("http://tinyurl.com/kgofxl8");
Document doc = con.get();
assertTrue(doc.title().contains("Google"));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method postRedirectsFetchWithGet.
@Test
public void postRedirectsFetchWithGet() throws IOException {
Connection con = Jsoup.connect("http://direct.infohound.net/tools/302.pl").data("Argument", "Riposte").method(Connection.Method.POST);
Connection.Response res = con.execute();
assertEquals("https://jsoup.org/", res.url().toExternalForm());
assertEquals(Connection.Method.GET, res.method());
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method ignoresExceptionIfSoConfigured.
@Test
public void ignoresExceptionIfSoConfigured() throws IOException {
Connection con = Jsoup.connect("http://direct.infohound.net/tools/404").ignoreHttpErrors(true);
Connection.Response res = con.execute();
Document doc = res.parse();
assertEquals(404, res.statusCode());
assertEquals("404 Not Found", doc.select("h1").first().text());
}
use of org.jsoup.Connection in project jsoup by jhy.
the class HttpConnectionTest method headers.
@Test
public void headers() {
Connection con = HttpConnection.connect("http://example.com");
Map<String, String> headers = new HashMap<String, String>();
headers.put("content-type", "text/html");
headers.put("Connection", "keep-alive");
headers.put("Host", "http://example.com");
con.headers(headers);
assertEquals("text/html", con.request().header("content-type"));
assertEquals("keep-alive", con.request().header("Connection"));
assertEquals("http://example.com", con.request().header("Host"));
}
Aggregations