当前位置: 首页>>代码示例>>Java>>正文


Java BasicHttpParams.setParameter方法代码示例

本文整理汇总了Java中org.apache.http.params.BasicHttpParams.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java BasicHttpParams.setParameter方法的具体用法?Java BasicHttpParams.setParameter怎么用?Java BasicHttpParams.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.params.BasicHttpParams的用法示例。


在下文中一共展示了BasicHttpParams.setParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDefaultApacheHttpParams

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private static HttpParams getDefaultApacheHttpParams()
{
    // Configuración necesaria del Apache
    // Parámetros copiados de los parámetros por defecto de AndroidHttpClient.newInstance(...)
    // podríamos crear un AndroidHttpClient y coger los parámetros pero el problema es que "hay que usarlo".
    // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/net/http/AndroidHttpClient.java?av=f
    BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter("http.useragent", "Apache-HttpClient/UNAVAILABLE (java 1.4)"); // Emulador 4.0.3  SE CAMBIARÁ más adelante
    httpParams.setIntParameter("http.socket.timeout", 60 * 1000);
    httpParams.setBooleanParameter("http.connection.stalecheck", false);
    httpParams.setIntParameter("http.connection.timeout", 60 * 1000);
    httpParams.setBooleanParameter("http.protocol.handle-redirects", false);
    httpParams.setIntParameter("http.socket.buffer-size", 8192);

    // AHORA cambiamos los que nos interesan para dejarlos por defecto
    httpParams.setParameter("http.useragent", USER_AGENT);  // Añadimos ItsNatDroidBrowser

    return httpParams;
}
 
开发者ID:jmarranz,项目名称:itsnat_droid,代码行数:20,代码来源:ItsNatDroidBrowserImpl.java

示例2: addHeaderAndParams

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
protected static void addHeaderAndParams(final HttpRequestBase request, final Map<String, String> params) {
	// add default header
	request.addHeader("User-Agent", userAgent);

	// add params
	if (params != null) {

		// map --> HttpParams
		BasicHttpParams myParams = new BasicHttpParams();
		for (String key : params.keySet()) {
			myParams.setParameter(key, params.get(key));
		}

		request.setParams(myParams);
	}
}
 
开发者ID:AndroidStudioTranslate,项目名称:Android-Studio-Translate-Tool,代码行数:17,代码来源:HttpClientUtil.java

示例3: getHttpParams

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
/**
   * HTTP参数配置
   * @return
   */
  public BasicHttpParams getHttpParams(){
  	
  	BasicHttpParams httpParams = new BasicHttpParams();
      
      // 设置每个路由最大连接数
      ConnPerRouteBean connPerRoute = new ConnPerRouteBean(30);
      ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);
      HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
// 从连接池中取连接的超时时间,设置为1秒
   ConnManagerParams.setTimeout(httpParams, mTimeout);
   ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
   ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
   // 读响应数据的超时时间
   HttpConnectionParams.setSoTimeout(httpParams, mTimeout);
   HttpConnectionParams.setConnectionTimeout(httpParams, mTimeout);
   HttpConnectionParams.setTcpNoDelay(httpParams, true);
   HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE);

   HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
   HttpProtocolParams.setUserAgent(httpParams,userAgent);
   //默认参数
      HttpClientParams.setRedirecting(httpParams, false);
      HttpClientParams.setCookiePolicy(httpParams,
              CookiePolicy.BROWSER_COMPATIBILITY);
      httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
return httpParams;
     
  }
 
开发者ID:bangqu,项目名称:eshow-android,代码行数:33,代码来源:AbHttpClient.java

示例4: __setHttpClientParams

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private void __setHttpClientParams(DefaultHttpClient httpClient)
{
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
    httpClient.setParams(params);
}
 
开发者ID:EspressifApp,项目名称:IOT-Espressif-Android,代码行数:8,代码来源:EspActionDeviceUpgradeLocal.java

示例5: freeze

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
/**
 * Initialize the connection.
 */
synchronized void freeze() {
    if (frozen) {
        return;
    }
    if (userAgent == null) {
        setDefaultUserAgent();
    }
    serviceMap = new HashMap<String, ServiceEndpoint>();
    if (log.isDebugEnabled()) {
        StringBuilder buf = new StringBuilder();
        buf.append("Creating MwsConnection {");
        buf.append("applicationName:");
        buf.append(applicationName);
        buf.append(",applicationVersion:");
        buf.append(applicationVersion);
        buf.append(",awsAccessKeyId:");
        buf.append(awsAccessKeyId);
        buf.append(",uri:");
        buf.append(endpoint.toString());
        buf.append(",userAgent:");
        buf.append(userAgent);
        buf.append(",connectionTimeout:");
        buf.append(connectionTimeout);
        if (proxyHost != null && proxyPort != 0) {
            buf.append(",proxyUsername:");
            buf.append(proxyUsername);
            buf.append(",proxyHost:");
            buf.append(proxyHost);
            buf.append(",proxyPort:");
            buf.append(proxyPort);
        }
        buf.append("}");
        log.debug(buf);
    }

    BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
    HttpConnectionParams
            .setConnectionTimeout(httpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);

    connectionManager = getConnectionManager();
    httpClient = new DefaultHttpClient(connectionManager, httpParams);
    httpContext = new BasicHttpContext();
    if (proxyHost != null && proxyPort != 0) {
        String scheme = MwsUtl.usesHttps(endpoint) ? "https" : "http";
        HttpHost hostConfiguration = new HttpHost(proxyHost, proxyPort, scheme);
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, hostConfiguration);

        if (proxyUsername != null && proxyPassword != null) {
            Credentials credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
            CredentialsProvider cprovider = new BasicCredentialsProvider();
            cprovider.setCredentials(new AuthScope(proxyHost, proxyPort), credentials);
            httpContext.setAttribute(ClientContext.CREDS_PROVIDER, cprovider);
        }
    }
    headers = Collections.unmodifiableMap(headers);
    frozen = true;
}
 
开发者ID:trifonnt,项目名称:ext-lib-amazon-mws-client-runtime,代码行数:65,代码来源:MwsConnection.java

示例6: createHttpRequest

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private static HttpUriRequest createHttpRequest(boolean isInstantly, boolean isGet, String url, JSONObject json,
    HeaderPair... headers)
{
    url = encodingUrl(url);
    if (!__isHttpsSupported())
    {
        url = url.replace("https", "http");
    }
    EspHttpRequest request = null;
    if (isGet)
    {
        request = new EspHttpRequest(url, EspHttpRequest.METHOD_GET);
    }
    else
    {
        request = new EspHttpRequest(url, EspHttpRequest.METHOD_POST);
    }
    if (isInstantly)
    {
        BasicHttpParams params = new BasicHttpParams();
        params.setParameter(EspHttpRequest.ESP_INSTANTLY, true);
        request.setParams(params);
    }
    // Add Headers
    for (int i = 0; i < headers.length; i++)
    {
        HeaderPair header = headers[i];
        request.addHeader(header.getName(), header.getValue());
    }
    // Set Entity
    if (json != null)
    {
        try
        {
            StringEntity se = new StringEntity(decoceJSON(json), HTTP.UTF_8);
            request.setEntity(se);
        }
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
            return null;
        }
    }
    return request;
}
 
开发者ID:EspressifApp,项目名称:IOT-Espressif-Android,代码行数:46,代码来源:EspHttpUtil.java

示例7: init

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private void init()
{
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
    params.setParameter("timemout", 6);
    this.setParams(params);
    // set keep alive strategy
    this.setKeepAliveStrategy(new ConnectionKeepAliveStrategy()
    {
        public long getKeepAliveDuration(HttpResponse response, HttpContext context)
        { // Honor 'keep-alive' header
            HeaderElementIterator it =
                new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext())
            {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout"))
                {
                    try
                    {
                        return Long.parseLong(value) * 1000;
                    }
                    catch (NumberFormatException ignore)
                    {
                    }
                }
            }
            Integer timeout = (Integer)context.getAttribute("timeout");
            if (timeout != null)
            {
                return timeout.longValue();
            }
            HttpHost target = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if ("iot.espressif.cn".equalsIgnoreCase(target.getHostName()))
            {
                // Keep alive for 30 seconds when connecting to server
                return 30 * 1000;
            }
            else
            {
                // otherwise keep alive for 8 seconds when connection to device
                return 10 * 1000;
            }
        }
    });
}
 
开发者ID:EspressifApp,项目名称:IOT-Espressif-Android,代码行数:50,代码来源:EspHttpClient.java

示例8: createClient

import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
public static DefaultHttpClient createClient(BasicHttpParams params, int maxRedirect) {
   	params.setParameter(ClientPNames.HANDLE_REDIRECTS, maxRedirect==0?Boolean.FALSE:Boolean.TRUE);
   	if(maxRedirect>0)params.setParameter(ClientPNames.MAX_REDIRECTS, new Integer(maxRedirect));
   	params.setParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, Boolean.FALSE);
   	return new DefaultHttpClient(params);
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:7,代码来源:HTTPEngine4Impl.java


注:本文中的org.apache.http.params.BasicHttpParams.setParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。