Search in sources :

Example 36 with Connection

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

Example 37 with Connection

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

Example 38 with Connection

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

Example 39 with Connection

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

Example 40 with Connection

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

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