use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method followsRedirectToHttps.
@Test
public void followsRedirectToHttps() throws IOException {
// https://www.google.com
Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-secure.pl");
con.data("id", "5");
Document doc = con.get();
assertTrue(doc.title().contains("Google"));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method followsRelativeDotRedirect2.
@Test
public void followsRelativeDotRedirect2() throws IOException {
//redirects to "esportspenedes.cat/./ep/index.php", should resolve to "esportspenedes.cat/ep/index.php"
Connection con = // note lack of trailing / - server should redir to / first, then to ./ep/...; but doesn't'
Jsoup.connect("http://esportspenedes.cat").timeout(10000);
Document doc = con.post();
assertEquals(doc.location(), "http://esportspenedes.cat/ep/index.php");
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method ignores500WithNoContentExceptionIfSoConfigured.
@Test
public void ignores500WithNoContentExceptionIfSoConfigured() throws IOException {
Connection con = Jsoup.connect("http://direct.infohound.net/tools/500-no-content.pl").ignoreHttpErrors(true);
Connection.Response res = con.execute();
Document doc = res.parse();
assertEquals(500, res.statusCode());
assertEquals("Application Error", res.statusMessage());
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method fetchHandlesXmlAsHtmlWhenParserSet.
@Test
public void fetchHandlesXmlAsHtmlWhenParserSet() throws IOException {
// should auto-detect xml and use XML parser, unless explicitly requested the html parser
String xmlUrl = "http://direct.infohound.net/tools/parse-xml.xml";
Connection con = Jsoup.connect(xmlUrl).parser(Parser.htmlParser());
Document doc = con.get();
Connection.Request req = con.request();
assertTrue(req.parser().getTreeBuilder() instanceof HtmlTreeBuilder);
assertEquals("<html> <head></head> <body> <xml> <link>one <table> Two </table> </xml> </body> </html>", StringUtil.normaliseWhitespace(doc.outerHtml()));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method doesntRedirectIfSoConfigured.
@Test
public void doesntRedirectIfSoConfigured() throws IOException {
Connection con = Jsoup.connect("http://direct.infohound.net/tools/302.pl").followRedirects(false);
Connection.Response res = con.execute();
assertEquals(302, res.statusCode());
assertEquals("http://jsoup.org", res.header("Location"));
}
Aggregations