示例#1
0
  /**
   * @param phost PROXY host name
   * @param pport PROXY port string
   * @param url URL string
   * @param headers Map
   */
  public HttpClient(
      String phost,
      int pport,
      String url,
      Map headers,
      String method,
      XmlHttpProxy.CookieCallback callback)
      throws MalformedURLException {
    this.callback = callback;

    if (phost != null && pport != -1) {
      this.isProxy = true;
    }

    this.proxyHost = phost;
    this.proxyPort = pport;

    if (url.trim().startsWith("https:")) {
      isHttps = true;
    }

    this.urlConnection = getURLConnection(url);
    try {
      this.urlConnection.setRequestMethod(method);
    } catch (java.net.ProtocolException pe) {
      HttpClient.getLogger().severe("Unable protocol method to " + method + " : " + pe);
    }
    this.headers = headers;
    writeHeaders(headers);
  }
示例#2
0
  /**
   * @param phost PROXY host name
   * @param pport PROXY port string
   * @param url URL string
   * @param headers Map
   * @param userName string
   * @param password string
   */
  public HttpClient(
      String phost,
      int pport,
      String url,
      Map headers,
      String method,
      String userName,
      String password,
      XmlHttpProxy.CookieCallback callback)
      throws MalformedURLException {

    this.callback = callback;

    try {
      if (phost != null && pport != -1) {
        this.isProxy = true;
      }

      this.proxyHost = phost;
      this.proxyPort = pport;
      if (url.trim().startsWith("https:")) {
        isHttps = true;
      }
      this.urlConnection = getURLConnection(url);
      try {
        this.urlConnection.setRequestMethod(method);
      } catch (java.net.ProtocolException pe) {
        HttpClient.getLogger().severe("Unable protocol method to " + method + " : " + pe);
      }
      // set basic authentication information
      String auth = userName + ":" + password;
      String encoded = new sun.misc.BASE64Encoder().encode(auth.getBytes());
      // set basic authorization
      this.urlConnection.setRequestProperty("Authorization", "Basic " + encoded);
      this.headers = headers;
      writeHeaders(headers);
    } catch (Exception ex) {
      HttpClient.getLogger()
          .severe("Unable to set basic authorization for " + userName + " : " + ex);
    }
  }