类org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory源码实例Demo

下面列出了怎么用org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: nutch-htmlunit   文件: Http.java
/**
 * Configures the HTTP client
 */
private void configureClient() {

  // Set up an HTTPS socket factory that accepts self-signed certs.
  ProtocolSocketFactory factory = new SSLProtocolSocketFactory();
  Protocol https = new Protocol("https", factory, 443);
  Protocol.registerProtocol("https", https);

  HttpConnectionManagerParams params = connectionManager.getParams();
  params.setConnectionTimeout(timeout);
  params.setSoTimeout(timeout);
  params.setSendBufferSize(BUFFER_SIZE);
  params.setReceiveBufferSize(BUFFER_SIZE);
  params.setMaxTotalConnections(maxThreadsTotal);

  // executeMethod(HttpMethod) seems to ignore the connection timeout on the connection manager.
  // set it explicitly on the HttpClient.
  client.getParams().setConnectionManagerTimeout(timeout);

  HostConfiguration hostConf = client.getHostConfiguration();
  ArrayList<Header> headers = new ArrayList<Header>();
  // Set the User Agent in the header
  headers.add(new Header("User-Agent", userAgent));
  // prefer English
  headers.add(new Header("Accept-Language", acceptLanguage));
  // prefer UTF-8
  headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7"));
  // prefer understandable formats
  headers.add(new Header("Accept",
          "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"));
  // accept gzipped content
  headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate"));
  hostConf.getParams().setParameter("http.default-headers", headers);

  // HTTP proxy server details
  if (useProxy) {
    hostConf.setProxy(proxyHost, proxyPort);

    if (proxyUsername.length() > 0) {

      AuthScope proxyAuthScope = getAuthScope(
          this.proxyHost, this.proxyPort, this.proxyRealm);

      NTCredentials proxyCredentials = new NTCredentials(
          this.proxyUsername, this.proxyPassword,
          Http.agentHost, this.proxyRealm);

      client.getState().setProxyCredentials(
          proxyAuthScope, proxyCredentials);
    }
  }

}
 
 类方法
 同包方法