Search in sources :

Example 1 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class HttpConnectionTest method throwsOnOddData.

@Test(expected = IllegalArgumentException.class)
public void throwsOnOddData() {
    Connection con = HttpConnection.connect("http://example.com/");
    con.data("Name", "val", "what");
}
Also used : Connection(org.jsoup.Connection) Test(org.junit.Test) ParseTest(org.jsoup.integration.ParseTest)

Example 2 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method sendHeadRequest.

@Test
public void sendHeadRequest() throws IOException {
    String url = "http://direct.infohound.net/tools/parse-xml.xml";
    Connection con = Jsoup.connect(url).method(Connection.Method.HEAD);
    final Connection.Response response = con.execute();
    assertEquals("text/xml", response.header("Content-Type"));
    // head ought to have no body
    assertEquals("", response.body());
    Document doc = response.parse();
    assertEquals("", doc.text());
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 3 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method ignores500tExceptionIfSoConfigured.

@Test
public void ignores500tExceptionIfSoConfigured() throws IOException {
    Connection con = Jsoup.connect("http://direct.infohound.net/tools/500.pl").ignoreHttpErrors(true);
    Connection.Response res = con.execute();
    Document doc = res.parse();
    assertEquals(500, res.statusCode());
    assertEquals("Application Error", res.statusMessage());
    assertEquals("Woops", doc.select("h1").first().text());
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 4 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method doesGet.

@Test
public void doesGet() throws IOException {
    Connection con = Jsoup.connect(echoURL + "?what=the").userAgent("Mozilla").referrer("http://example.com").data("what", "about & me?");
    Document doc = con.get();
    assertEquals("what=the&what=about+%26+me%3F", ihVal("QUERY_STRING", doc));
    assertEquals("the, about & me?", ihVal("what", doc));
    assertEquals("Mozilla", ihVal("HTTP_USER_AGENT", doc));
    assertEquals("http://example.com", ihVal("HTTP_REFERER", doc));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 5 with Connection

use of org.jsoup.Connection in project jsoup by jhy.

the class UrlConnectTest method followsRelativeRedirect.

@Test
public void followsRelativeRedirect() throws IOException {
    // to /tidy/
    Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-rel.pl");
    Document doc = con.post();
    assertTrue(doc.title().contains("HTML Tidy Online"));
}
Also used : Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Aggregations

Connection (org.jsoup.Connection)46 Test (org.junit.Test)42 Document (org.jsoup.nodes.Document)25 ParseTest (org.jsoup.integration.ParseTest)13 IOException (java.io.IOException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)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 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Proxy (java.net.Proxy)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 TaskException (org.aisen.android.network.task.TaskException)1 LikeResultBean (org.aisen.weibo.sina.support.bean.LikeResultBean)1