use of org.jsoup.Connection in project jsoup by jhy.
the class HttpConnectionTest method userAgent.
@Test
public void userAgent() {
Connection con = HttpConnection.connect("http://example.com/");
assertEquals(HttpConnection.DEFAULT_UA, con.request().header("User-Agent"));
con.userAgent("Mozilla");
assertEquals("Mozilla", con.request().header("User-Agent"));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method fetchHandlesXml.
@Test
public void fetchHandlesXml() 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);
Document doc = con.get();
Connection.Request req = con.request();
assertTrue(req.parser().getTreeBuilder() instanceof XmlTreeBuilder);
assertEquals("<xml> <link> one </link> <table> Two </table> </xml>", StringUtil.normaliseWhitespace(doc.outerHtml()));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method fetchURIWithWihtespace.
@Test
public void fetchURIWithWihtespace() throws IOException {
Connection con = Jsoup.connect("http://try.jsoup.org/#with whitespaces");
Document doc = con.get();
assertTrue(doc.title().contains("jsoup"));
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method handles200WithNoContent.
@Test
public void handles200WithNoContent() throws IOException {
Connection con = Jsoup.connect("http://direct.infohound.net/tools/200-no-content.pl").userAgent(browserUa);
Connection.Response res = con.execute();
Document doc = res.parse();
assertEquals(200, res.statusCode());
con = Jsoup.connect("http://direct.infohound.net/tools/200-no-content.pl").parser(Parser.xmlParser()).userAgent(browserUa);
res = con.execute();
doc = res.parse();
assertEquals(200, res.statusCode());
}
use of org.jsoup.Connection in project jsoup by jhy.
the class UrlConnectTest method gracefullyHandleBrokenLocationRedirect.
@Test
public void gracefullyHandleBrokenLocationRedirect() throws IOException {
// has Location: http:/temp/AAG_New/en/index.php
Connection con = Jsoup.connect("http://aag-ye.com");
// would throw exception on error
con.get();
assertTrue(true);
}
Aggregations