Пример #1
0
  /**
   * Append given parameters to the query string of the url
   *
   * @param url the url to append parameters to
   * @param params any map
   * @return new url with parameters on query string
   */
  public static String appendParametersToQueryString(String url, Map<String, String> params) {
    String queryString = URLUtils.formURLEncodeMap(params);
    if (queryString.length() == 0) return url;

    // Check if there are parameters in the url already and use '&' instead of '?'
    url += url.indexOf(QUERY_STRING_SEPARATOR) != -1 ? PARAM_SEPARATOR : QUERY_STRING_SEPARATOR;
    url += queryString;
    return url;
  }
Пример #2
0
 byte[] getByteBodyContents() {
   if (bytePayload != null) return bytePayload;
   String body = null;
   if (payload != null) {
     body = payload;
   } else if (files.isEmpty()) {
     body = URLUtils.formURLEncodeMap(bodyParams);
   } else {
     byte res[] = null;
     try {
       res = URLUtils.doFormDataEncode(bodyParams, files, boundary).toByteArray();
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     return res;
   }
   try {
     return body.getBytes(getCharset());
   } catch (UnsupportedEncodingException uee) {
     throw new OAuthException("Unsupported Charset: " + getCharset(), uee);
   }
 }
Пример #3
0
  private void createConnection() throws IOException {
    String effectiveUrl = URLUtils.appendParametersToQueryString(url, querystringParams);
    if (connection == null) {
      System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false");
      // connection = (HttpURLConnection) new URL(effectiveUrl).openConnection();

      URL url = new URL(effectiveUrl);
      if (url.getProtocol().toLowerCase().equals("https")) {
        trustAllHosts();
        HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
        https.setHostnameVerifier(DO_NOT_VERIFY);
        connection = https;
      } else {
        connection = (HttpURLConnection) url.openConnection();
      }
    }
  }