public byte[] postAsBody(String url, byte[] body, String mime, String charset)
    throws HttpException {

    int numRetries = retry ? maxRetries : 1;
    HttpPost httppost = null;

    for (int i = 0; i < numRetries; i++) {
      try {

        httppost = new HttpPost(url);
        httppost.setHeader("Content-Type", mime + ";" + "charset=" + charset);
        httppost.setEntity(new ByteArrayEntity(body));

        HttpResponse response = httpClient.execute(httppost);
        StatusLine status = response.getStatusLine();
        int statusCode = status.getStatusCode();
        if (statusCode >= 300) {
          throw new HttpException(status.getReasonPhrase());
        }

        HttpEntity entity = response.getEntity();
        if (entity != null) {
          return EntityUtils.toByteArray(entity);
        }

        return null;
      }
      catch (HttpException he) {
        httppost.abort();
        throw he;
      }
      catch (Exception e) {
        httppost.abort();
      }
    }

    // tried max times and errored, throw exception
    throw new HttpException("POST error: " + url + ", attempts:" + numRetries);
  }