Search in sources :

Example 31 with Connection

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"));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 32 with Connection

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");
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 33 with Connection

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());
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 34 with Connection

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()));
}
Also used : HtmlTreeBuilder(org.jsoup.parser.HtmlTreeBuilder) Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 35 with Connection

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"));
}
Also used : Connection(org.jsoup.Connection) Test(org.junit.Test)

Aggregations

Connection (org.jsoup.Connection)47 Test (org.junit.Test)42 Document (org.jsoup.nodes.Document)26 ParseTest (org.jsoup.integration.ParseTest)13 IOException (java.io.IOException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 News (com.itculturalfestival.smartcampus.entity.News)1 DisposableHolder (com.vegen.smartcampus.baseframework.network.DisposableHolder)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 Disposable (io.reactivex.disposables.Disposable)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1