private void buildRequest(HttpURLConnection uc) throws IOException { if (!method.equals("GET")) { uc.setDoOutput(true); uc.setRequestProperty("Content-type", contentType); if (body == null) { Map json = new HashMap(); for (Entry e : args) { json.put(e.key, e.value); } MAPPER.writeValue(uc.getOutputStream(), json); } else { try { byte[] bytes = new byte[32768]; int read = 0; while ((read = body.read(bytes)) != -1) { uc.getOutputStream().write(bytes, 0, read); } } finally { body.close(); } } } }