Package com.jcabi.http.response
Class JsoupResponse
java.lang.Object
com.jcabi.http.response.JsoupResponse
- All Implemented Interfaces:
Response
Jsoup response.
This response decorator is able to parse HTTP response body as an HTML document. Example usage:
String body = new JdkRequest("http://my.example.com")
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
.fetch()
.as(JsoupResponse.class)
.body();
body() will try to output clean HTML even for
malformed responses. For example:
- Unclosed tags will be closed ("<p>Hello" will become "<p>Hello</p>")
- Implicit tags will be made explicit (e.g. a naked <td> will be wrapped in a <table><tr><td>)
- Basic structure is guaranteed (i.e. html, head, body elements)
The class is immutable and thread-safe.
- Since:
- 1.4
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <T extends Response>
TConvert it to another type, by encapsulation.final Requestback()Get back to the request it's related to.final byte[]binary()Raw body as an array of bytes.body()Get body as a string, assuming it'sUTF-8(if there is something else that can't be translated into a UTF-8 string a runtime exception will be thrown).headers()Get a collection of all headers.final Stringreason()Get status line reason phrase.final intstatus()Get status of the response as a positive integer number.final StringtoString()
-
Constructor Details
-
JsoupResponse
Public ctor.- Parameters:
resp- Response
-
-
Method Details
-
body
Description copied from interface:ResponseGet body as a string, assuming it'sUTF-8(if there is something else that can't be translated into a UTF-8 string a runtime exception will be thrown).DISCLAIMER: The only encoding supported here is UTF-8. If the body of response contains any chars that can't be used and should be replaced with a "replacement character", a
RuntimeExceptionwill be thrown. If you need to use some other encodings, useResponse.binary()instead. -
toString
-
back
Description copied from interface:ResponseGet back to the request it's related to. -
status
public final int status()Description copied from interface:ResponseGet status of the response as a positive integer number. -
reason
Description copied from interface:ResponseGet status line reason phrase. -
headers
Description copied from interface:ResponseGet a collection of all headers. -
binary
public final byte[] binary()Description copied from interface:ResponseRaw body as an array of bytes. -
as
Description copied from interface:ResponseConvert it to another type, by encapsulation.
-