title: Receiving binary data over HTTP
body: <p>I have a server which is sending a .png image to a client via a HTTP post request. The .png is stored inside a sqlite3 database, retrieved as a blob and this all works fine; I have tested saving the returned blob to disk and it can be opened as expected. When my client interprets the response, the payload has mysteriously grown in length from 16365 to 16367, inspecting the response string has shown there are some extra '?' characters intermittently in the stream</p>
  
  <p>Testing the server using the ARC plug-in for Chrome has shown the response received there to be the right length, which leads me to believe there is a problem with my client code:</p>
  
  <pre><code>// request
  URL url = new URL(targetURL);
  conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("POST");
  conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  conn.setRequestProperty("Content-Length", Integer.toString(parameters.getBytes().length));
  conn.setRequestProperty("Content-Language", "en-US");
  conn.setUseCaches(false);
  conn.setDoOutput(true);
  conn.getOutputStream().write(parameters.getBytes());
  
  // response
  Reader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  StringBuilder sb = new StringBuilder();
  for (int c; (c = rd.read()) &gt;=0;)
      sb.append((char)c);
  String response = sb.toString();
  // this String is of length 16367 when it should be 16365
  </code></pre>
  
  <p>Does anything jump out as being incorrect here? Note I am not doing any kind of character encoding on either side, should I be when using raw image data?</p>