use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method ignoresContentTypeIfSoConfigured.
@Test
public void ignoresContentTypeIfSoConfigured() throws IOException {
Document doc = Jsoup.connect("https://jsoup.org/rez/osi_logo.png").ignoreContentType(true).get();
// this will cause an ugly parse tree
assertEquals("", doc.title());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method sendsRequestBody.
@Test
public void sendsRequestBody() throws IOException {
final String body = "{key:value}";
Document doc = Jsoup.connect(echoURL).requestBody(body).header("Content-Type", "text/plain").userAgent(browserUa).post();
assertEquals("POST", ihVal("REQUEST_METHOD", doc));
assertEquals("text/plain", ihVal("CONTENT_TYPE", doc));
assertEquals(body, doc.select("th:contains(POSTDATA) ~ td").text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method handlesUnescapedRedirects.
@Test
public void handlesUnescapedRedirects() throws IOException {
// URL locations should be url safe (ascii) but are often not, so we should try to guess
// in this case the location header is utf-8, but defined in spec as iso8859, so detect, convert, encode
String url = "http://direct.infohound.net/tools/302-utf.pl";
String urlEscaped = "http://direct.infohound.net/tools/test%F0%9F%92%A9.html";
Connection.Response res = Jsoup.connect(url).execute();
Document doc = res.parse();
assertEquals(doc.body().text(), "💩!");
assertEquals(doc.location(), urlEscaped);
Connection.Response res2 = Jsoup.connect(url).followRedirects(false).execute();
assertEquals("/tools/test💩.html", res2.header("Location"));
// if we didn't notice it was utf8, would look like: Location: /tools/test💩.html
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method sendsRequestBodyWithUrlParams.
@Test
public void sendsRequestBodyWithUrlParams() throws IOException {
final String body = "{key:value}";
Document doc = Jsoup.connect(echoURL).requestBody(body).data("uname", "Jsoup", "uname", "Jonathan", "百", "度一下").header("Content-Type", // todo - if user sets content-type, we should append postcharset
"text/plain").userAgent(browserUa).post();
assertEquals("POST", ihVal("REQUEST_METHOD", doc));
assertEquals("uname=Jsoup&uname=Jonathan&%E7%99%BE=%E5%BA%A6%E4%B8%80%E4%B8%8B", ihVal("QUERY_STRING", doc));
assertEquals(body, ihVal("POSTDATA", doc));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class UrlConnectTest method inWildUtfRedirect.
@Test
public void inWildUtfRedirect() throws IOException {
Connection.Response res = Jsoup.connect("http://brabantn.ws/Q4F").execute();
Document doc = res.parse();
assertEquals("http://www.omroepbrabant.nl/?news/2474781303/Gestrande+ree+in+Oss+niet+verdoofd,+maar+doodgeschoten+%E2%80%98Dit+kan+gewoon+niet,+bizar%E2%80%99+[VIDEO].aspx", doc.location());
}
Aggregations