public byte[] post(String url, Map<String, String> postParams)
    throws HttpException {

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

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    if (postParams != null && !postParams.isEmpty()) {
      for (Map.Entry<String, String> param : postParams.entrySet()) {
        nameValuePairs.add(new BasicNameValuePair(param.getKey(), param
          .getValue()));
      }
    }

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

      try {

        httppost = new HttpPost(url);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        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);
  }