Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should rather have obtained the response as an <a href="http://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html" rel="nofollow noreferrer"><code>InputStream</code></a> instead of as <code>byte[]</code>. Then you can ungzip it using <a href="http://docs.oracle.com/javase/8/docs/api/java/util/zip/GZIPInputStream.html" rel="nofollow noreferrer"><code>GZIPInputStream</code></a> and read it as character data using <a href="http://docs.oracle.com/javase/8/docs/api/java/io/InputStreamReader.html" rel="nofollow noreferrer"><code>InputStreamReader</code></a> and finally write it as character data into a <code>String</code> using <a href="http://docs.oracle.com/javase/8/docs/api/java/io/StringWriter.html" rel="nofollow noreferrer"><code>StringWriter</code></a>.</p> <pre><code>String body = null; String charset = "UTF-8"; // You should determine it based on response header. try ( InputStream gzippedResponse = response.getInputStream(); InputStream ungzippedResponse = new GZIPInputStream(gzippedResponse); Reader reader = new InputStreamReader(ungzippedResponse, charset); Writer writer = new StringWriter(); ) { char[] buffer = new char[10240]; for (int length = 0; (length = reader.read(buffer)) &gt; 0;) { writer.write(buffer, 0, length); } body = writer.toString(); } // ... </code></pre> <h3>See also:</h3> <ul> <li><a href="http://docs.oracle.com/javase/tutorial/essential/io/" rel="nofollow noreferrer">Java IO tutorial</a></li> <li><a href="https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests">How to use URLConnecion to fire/handle HTTP requests</a></li> </ul> <hr> <p>If your final intent is to parse the response as HTML, then I strongly recommend to just use a HTML parser for this like <a href="http://jsoup.org" rel="nofollow noreferrer">Jsoup</a>. It's then as easy as:</p> <pre><code>String html = Jsoup.connect("http://google.com").get().html(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload