當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientParams.setContentCharset方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.params.HttpClientParams.setContentCharset方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientParams.setContentCharset方法的具體用法?Java HttpClientParams.setContentCharset怎麽用?Java HttpClientParams.setContentCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.params.HttpClientParams的用法示例。


在下文中一共展示了HttpClientParams.setContentCharset方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.apache.commons.httpclient.params.HttpClientParams; //導入方法依賴的package包/類
private synchronized void init() {
	client = new HttpClient(new MultiThreadedHttpConnectionManager());
	HttpClientParams params = client.getParams();
	if (encode != null && !encode.trim().equals("")) {
		params.setParameter("http.protocol.content-charset", encode);
		params.setContentCharset(encode);
	}
	if (timeout > 0) {
		params.setSoTimeout(timeout);
	}
	if (null != proxy) {
		HostConfiguration hc = new HostConfiguration();
		hc.setProxy(proxy.getHost(), proxy.getPort());
		client.setHostConfiguration(hc);
		client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword()));
	}
	initialized = true;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:19,代碼來源:HttpUtil.java

示例2: buildClient

import org.apache.commons.httpclient.params.HttpClientParams; //導入方法依賴的package包/類
/**
 * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
 * been created.
 * 
 * @return the created client.
 */
public HttpClient buildClient() {
    if (httpsProtocolSocketFactory != null) {
        Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
    clientParams.setContentCharset(getContentCharSet());
    clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            connectionRetryAttempts, false));

    HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
    connMgrParams.setConnectionTimeout(getConnectionTimeout());
    connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
    connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
    connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
    connMgrParams.setSendBufferSize(getSendBufferSize());
    connMgrParams.setTcpNoDelay(isTcpNoDelay());

    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    connMgr.setParams(connMgrParams);

    HttpClient httpClient = new HttpClient(clientParams, connMgr);

    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        httpClient.setHostConfiguration(hostConfig);

        if (proxyUsername != null) {
            AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
            UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
                    proxyPassword);
            httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

    return httpClient;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,代碼來源:HttpClientBuilder.java

示例3: start

import org.apache.commons.httpclient.params.HttpClientParams; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void start() throws HomematicClientException {
	logger.info("Starting {}", CcuClient.class.getSimpleName());
	super.start();

	tclregaScripts = loadTclRegaScripts();

	httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
	HttpClientParams params = httpClient.getParams();
	Long timeout = context.getConfig().getTimeout() * 1000L;
	params.setConnectionManagerTimeout(timeout);
	params.setSoTimeout(timeout.intValue());
	params.setContentCharset("ISO-8859-1");
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:18,代碼來源:CcuClient.java

示例4: start

import org.apache.commons.httpclient.params.HttpClientParams; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void start() throws HomematicClientException {
    logger.info("Starting {}", CcuClient.class.getSimpleName());
    super.start();

    tclregaScripts = loadTclRegaScripts();

    httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
    HttpClientParams params = httpClient.getParams();
    Long timeout = context.getConfig().getTimeout() * 1000L;
    params.setConnectionManagerTimeout(timeout);
    params.setSoTimeout(timeout.intValue());
    params.setContentCharset("ISO-8859-1");
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:18,代碼來源:CcuClient.java

示例5: CommonsHttpTransport

import org.apache.commons.httpclient.params.HttpClientParams; //導入方法依賴的package包/類
public CommonsHttpTransport(Settings settings, String host) {
    this.settings = settings;
    httpInfo = host;
    sslEnabled = settings.getNetworkSSLEnabled();

    String pathPref = settings.getNodesPathPrefix();
    pathPrefix = (StringUtils.hasText(pathPref) ? addLeadingSlashIfNeeded(StringUtils.trimWhitespace(pathPref)) : StringUtils.trimWhitespace(pathPref));

    HttpClientParams params = new HttpClientParams();
    params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            settings.getHttpRetries(), false) {

        @Override
        public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
            if (super.retryMethod(method, exception, executionCount)) {
                stats.netRetries++;
                return true;
            }
            return false;
        }
    });

    params.setConnectionManagerTimeout(settings.getHttpTimeout());
    params.setSoTimeout((int) settings.getHttpTimeout());
    // explicitly set the charset
    params.setCredentialCharset(StringUtils.UTF_8.name());
    params.setContentCharset(StringUtils.UTF_8.name());

    HostConfiguration hostConfig = new HostConfiguration();

    hostConfig = setupSSLIfNeeded(settings, hostConfig);
    hostConfig = setupSocksProxy(settings, hostConfig);
    Object[] authSettings = setupHttpOrHttpsProxy(settings, hostConfig);
    hostConfig = (HostConfiguration) authSettings[0];

    try {
        hostConfig.setHost(new URI(escapeUri(host, sslEnabled), false));
    } catch (IOException ex) {
        throw new EsHadoopTransportException("Invalid target URI " + host, ex);
    }
    client = new HttpClient(params, new SocketTrackingConnectionManager());
    client.setHostConfiguration(hostConfig);

    addHttpAuth(settings, authSettings);
    completeAuth(authSettings);

    HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
    // make sure to disable Nagle's protocol
    connectionParams.setTcpNoDelay(true);

    if (log.isTraceEnabled()) {
        log.trace("Opening HTTP transport to " + httpInfo);
    }
}
 
開發者ID:xushjie1987,項目名稱:es-hadoop-v2.2.0,代碼行數:55,代碼來源:CommonsHttpTransport.java

示例6: CommonsHttpTransport

import org.apache.commons.httpclient.params.HttpClientParams; //導入方法依賴的package包/類
public CommonsHttpTransport(Settings settings, String host) {
    this.settings = settings;
    httpInfo = host;
    sslEnabled = settings.getNetworkSSLEnabled();

    String pathPref = settings.getNodesPathPrefix();
    pathPrefix = (StringUtils.hasText(pathPref) ? addLeadingSlashIfNeeded(StringUtils.trimWhitespace(pathPref)) : StringUtils.trimWhitespace(pathPref));

    HttpClientParams params = new HttpClientParams();
    params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            settings.getHttpRetries(), false) {

        @Override
        public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
            if (super.retryMethod(method, exception, executionCount)) {
                stats.netRetries++;
                return true;
            }
            return false;
        }
    });

    params.setConnectionManagerTimeout(settings.getHttpTimeout());
    params.setSoTimeout((int) settings.getHttpTimeout());
    // explicitly set the charset
    params.setCredentialCharset(StringUtils.UTF_8.name());
    params.setContentCharset(StringUtils.UTF_8.name());

    HostConfiguration hostConfig = new HostConfiguration();

    hostConfig = setupSSLIfNeeded(settings, hostConfig);
    hostConfig = setupSocksProxy(settings, hostConfig);
    Object[] authSettings = setupHttpOrHttpsProxy(settings, hostConfig);
    hostConfig = (HostConfiguration) authSettings[0];

    try {
        hostConfig.setHost(new URI(escapeUri(host, sslEnabled), false));
    } catch (IOException ex) {
        throw new EsHadoopTransportException("Invalid target URI " + host, ex);
    }
    client = new HttpClient(params, new SocketTrackingConnectionManager());
    client.setHostConfiguration(hostConfig);

    addHttpAuth(settings, authSettings);
    completeAuth(authSettings);

    HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
    // make sure to disable Nagle's protocol
    connectionParams.setTcpNoDelay(true);

    this.headers = new HeaderProcessor(settings);

    if (log.isTraceEnabled()) {
        log.trace("Opening HTTP transport to " + httpInfo);
    }
}
 
開發者ID:elastic,項目名稱:elasticsearch-hadoop,代碼行數:57,代碼來源:CommonsHttpTransport.java


注:本文中的org.apache.commons.httpclient.params.HttpClientParams.setContentCharset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。