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


Java HttpProtocolParams.setUserAgent方法代碼示例

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


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

示例1: a

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public static b a(String str) {
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
    HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
    HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
    HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
    HttpClientParams.setRedirecting(basicHttpParams, true);
    HttpClientParams.setAuthenticating(basicHttpParams, false);
    HttpProtocolParams.setUserAgent(basicHttpParams, str);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
    ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
    ConnManagerParams.setTimeout(basicHttpParams, 60000);
    ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
    ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
    Security.setProperty("networkaddress.cache.ttl", "-1");
    HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
    return new b(threadSafeClientConnManager, basicHttpParams);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:b.java

示例2: getHttpClient

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
 * 從可用的HttpClient池中返回一個默認10秒的HttpClient對象,該方法是同步的。
 * 
 * @return 可用的.HttpClient對象
 */
public static synchronized HttpClient getHttpClient() {
	if (null == customerHttpClient) {
		HttpParams params = new BasicHttpParams();
		HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
		HttpProtocolParams.setContentCharset(params, CHARSET);
		HttpProtocolParams.setUseExpectContinue(params, true);
		HttpProtocolParams.setUserAgent(params,
						"Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) "
								+ "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");
		ConnManagerParams.setTimeout(params, 10000);

		HttpConnectionParams.setConnectionTimeout(params, 10000);

		HttpConnectionParams.setSoTimeout(params, 10000);

		SchemeRegistry schReg = new SchemeRegistry();
		schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
		schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

		ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
		customerHttpClient = new DefaultHttpClient(conMgr, params);
	}
	return customerHttpClient;
}
 
開發者ID:iOnesmile,項目名稱:MyAndroidDemo,代碼行數:30,代碼來源:CustomerHttpClient.java

示例3: newInstance

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public static AndroidHttpClient newInstance(String paramString, Context paramContext)
{
  BasicHttpParams localBasicHttpParams = new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(localBasicHttpParams, false);
  HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 20000);
  HttpConnectionParams.setSoTimeout(localBasicHttpParams, 20000);
  HttpConnectionParams.setSocketBufferSize(localBasicHttpParams, 8192);
  HttpClientParams.setRedirecting(localBasicHttpParams, false);
  if (paramContext == null) {}
  for (SSLSessionCache localSSLSessionCache = null;; localSSLSessionCache = new SSLSessionCache(paramContext))
  {
    HttpProtocolParams.setUserAgent(localBasicHttpParams, paramString);
    SchemeRegistry localSchemeRegistry = new SchemeRegistry();
    localSchemeRegistry.register(new Scheme("http", ElegantPlainSocketFactory.getSocketFactory(), 80));
    localSchemeRegistry.register(new Scheme("https", getSocketFactory(localSSLSessionCache), 443));
    ConnManagerParamBean localConnManagerParamBean = new ConnManagerParamBean(localBasicHttpParams);
    localConnManagerParamBean.setConnectionsPerRoute(new ConnPerRouteBean(4));
    localConnManagerParamBean.setMaxTotalConnections(8);
    return new AndroidHttpClient(new ElegantThreadSafeConnManager(localBasicHttpParams, localSchemeRegistry), localBasicHttpParams);
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:22,代碼來源:AndroidHttpClient.java

示例4: getHttpClient

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public HttpClient getHttpClient() {  
    // 創建 HttpParams 以用來設置 HTTP 參數(這一部分不是必需的)  
    this.httpParams = new BasicHttpParams();  
    // 設置連接超時和 Socket 超時,以及 Socket 緩存大小  
    HttpConnectionParams.setConnectionTimeout(httpParams, 20 * 1000);  
    HttpConnectionParams.setSoTimeout(httpParams, 20 * 1000);  
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);  
    // 設置重定向,缺省為 true  
    HttpClientParams.setRedirecting(httpParams, true);  
    // 設置 user agent  
    String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";  
    HttpProtocolParams.setUserAgent(httpParams, userAgent);  
    // 創建一個 HttpClient 實例  
    // 注意 HttpClient httpClient = new HttpClient(); 是Commons HttpClient  
    // 中的用法,在 Android 1.5 中我們需要使用 Apache 的缺省實現 DefaultHttpClient  
    httpClient = new DefaultHttpClient(httpParams);  
    return httpClient;  
}
 
開發者ID:reallin,項目名稱:CrashHandler,代碼行數:19,代碼來源:CrashHandler.java

示例5: initHttpConnection

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
 * Prepares objects for HTTP communications with the Gatekeeper servlet.
 * @return
 */
private HttpClient initHttpConnection() {
    // Set client parameters.
    HttpParams params = RestUtils.createDefaultHttpParams();
    HttpProtocolParams.setUserAgent(
          params,
          ServiceUtils.getUserAgentDescription(userAgentDescription));

    // Set connection parameters.
    HttpConnectionParams.setConnectionTimeout(
          params,
          connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, connectionTimeout);
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    DefaultHttpClient httpClient = new DefaultHttpClient(params);
    // Replace default error retry handler.
    httpClient.setHttpRequestRetryHandler(new RestUtils.JetS3tRetryHandler(
          maxRetryCount,
          null));

    // httpClient.getParams().setAuthenticationPreemptive(true);
    httpClient.setCredentialsProvider(credentialsProvider);

    return httpClient;
}
 
開發者ID:guptavishal,項目名稱:jets3t-aws-roles,代碼行數:30,代碼來源:GatekeeperClientUtils.java

示例6: ToopherAPI

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
 * Create an API object with the supplied credentials, overriding the default API URI of https://api.toopher.com/v1/
 *
 * @param consumerKey
 *            The consumer key for a requester (obtained from the developer portal)
 * @param consumerSecret
 *            The consumer secret for a requester (obtained from the developer portal)
 * @param uri
 *            The alternate URI
 */
public ToopherAPI(String consumerKey, String consumerSecret, URI uri) {
    httpClient = new DefaultHttpClient();
    HttpProtocolParams.setUserAgent(httpClient.getParams(),
                                    String.format("ToopherJava/%s", VERSION));

    consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
    if (uri == null) {
        this.uriScheme = ToopherAPI.DEFAULT_URI_SCHEME;
        this.uriHost = ToopherAPI.DEFAULT_URI_HOST;
        this.uriPort = ToopherAPI.DEFAULT_URI_PORT;
        this.uriBase = ToopherAPI.DEFAULT_URI_BASE;
    } else {
        this.uriScheme = uri.getScheme();
        this.uriHost = uri.getHost();
        this.uriPort = uri.getPort();
        this.uriBase = uri.getPath();
    }
}
 
開發者ID:toopher,項目名稱:toopher-pingfederate,代碼行數:29,代碼來源:ToopherAPI.java

示例7: setDefaultHttpParams

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
 * Saves the default set of HttpParams in the provided parameter.
 * These are:
 * <ul>
 * <li>{@link CoreProtocolPNames#PROTOCOL_VERSION}: 1.1</li>
 * <li>{@link CoreProtocolPNames#HTTP_CONTENT_CHARSET}: ISO-8859-1</li>
 * <li>{@link CoreConnectionPNames#TCP_NODELAY}: true</li>
 * <li>{@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}: 8192</li>
 * <li>{@link CoreProtocolPNames#USER_AGENT}: Apache-HttpClient/<release> (java 1.5)</li>
 * </ul>
 */
public static void setDefaultHttpParams(HttpParams params) {
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo
        ("org.apache.http.client", DefaultHttpClient.class.getClassLoader());
    final String release = (vi != null) ?
        vi.getRelease() : VersionInfo.UNAVAILABLE;
    HttpProtocolParams.setUserAgent(params,
            "Apache-HttpClient/" + release + " (java 1.5)");
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:DefaultHttpClient.java

示例8: a

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public static b a() {
    if (b == null) {
        HttpParams basicHttpParams = new BasicHttpParams();
        HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
        HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, true);
        basicHttpParams.setBooleanParameter("http.protocol.expect-continue", false);
        ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
        ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(30));
        ConnManagerParams.setTimeout(basicHttpParams, 1000);
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
        HttpConnectionParams.setSocketBufferSize(basicHttpParams, 16384);
        HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
        HttpClientParams.setRedirecting(basicHttpParams, true);
        HttpClientParams.setAuthenticating(basicHttpParams, false);
        HttpProtocolParams.setUserAgent(basicHttpParams, a);
        try {
            SocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
            socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme scheme = new Scheme(com.alipay.sdk.cons.b.a, socketFactory, WebSocket.DEFAULT_WSS_PORT);
            Scheme scheme2 = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(scheme);
            schemeRegistry.register(scheme2);
            b = new b(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
        } catch (Exception e) {
            b = new b(basicHttpParams);
        }
    }
    return b;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:32,代碼來源:b.java

示例9: getHttpParams

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
	 * 設置http參數 不能設置soTimeout
	 * @return HttpParams http參數
	 */
	private static HttpParams getHttpParams() {
		HttpParams params = new BasicHttpParams();

		HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
		HttpProtocolParams.setUseExpectContinue(params, true);
		HttpProtocolParams.setUserAgent(params, UA);
//		ConnManagerParams.setTimeout(params, 10000);
//		HttpConnectionParams.setConnectionTimeout(params, 10000);
		
		return params;
	}
 
開發者ID:qibin0506,項目名稱:LitePlayer,代碼行數:16,代碼來源:Download.java

示例10: getParams

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public static HttpParams getParams() {
	HttpParams params = new BasicHttpParams();
	HttpConnectionParams.setConnectionTimeout(params, 4000);
	HttpConnectionParams.setSoTimeout(params, 10000);
	ConnManagerParams.setTimeout(params, 4000);
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
	HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
	HttpProtocolParams.setUseExpectContinue(params, true);
	HttpProtocolParams.setUserAgent(params, "Mozilla/5.0 (Windows NT 6.1; WOW64)" +
			" AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1941.0 Safari/537.36");
	return params;
}
 
開發者ID:qibin0506,項目名稱:LitePlayer,代碼行數:13,代碼來源:HttpUtils.java

示例11: getHttpParams

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的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

示例12: newInstance

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 *
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent) {
  HttpParams params = new BasicHttpParams();

  // Turn off stale checking. Our connections break all the time anyway,
  // and it's not worth it to pay the penalty of checking every time.
  HttpConnectionParams.setStaleCheckingEnabled(params, false);

  // Default connection and socket timeout of 20 seconds. Tweak to taste.
  HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
  HttpConnectionParams.setSoTimeout(params, 20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params, 8192);

  // Don't handle redirects -- return them to the caller. Our code
  // often wants to re-POST after a redirect, which we must do ourselves.
  HttpClientParams.setRedirecting(params, false);

  // Set the specified user agent and register standard protocols.
  HttpProtocolParams.setUserAgent(params, userAgent);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
  ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

  // We use a factory method to modify superclass initialization
  // parameters without the funny call-a-static-method dance.
  return new AndroidHttpClient(manager, params);
}
 
開發者ID:playn,項目名稱:playn,代碼行數:34,代碼來源:AndroidHttpClient.java

示例13: newInstance

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 *
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent) {
  HttpParams params = new BasicHttpParams();

  // Turn off stale checking.  Our connections break all the time anyway,
  // and it's not worth it to pay the penalty of checking every time.
  HttpConnectionParams.setStaleCheckingEnabled(params, false);

  // Default connection and socket timeout of 20 seconds.  Tweak to taste.
  HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
  HttpConnectionParams.setSoTimeout(params, 20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params, 8192);

  // Don't handle redirects -- return them to the caller.  Our code
  // often wants to re-POST after a redirect, which we must do ourselves.
  HttpClientParams.setRedirecting(params, false);

  // Set the specified user agent and register standard protocols.
  HttpProtocolParams.setUserAgent(params, userAgent);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",
      PlainSocketFactory.getSocketFactory(), 80));
  schemeRegistry.register(new Scheme("https",
      SSLSocketFactory.getSocketFactory(), 443));
  ClientConnectionManager manager =
      new ThreadSafeClientConnManager(params, schemeRegistry);

  // We use a factory method to modify superclass initialization
  // parameters without the funny call-a-static-method dance.
  return new AndroidHttpClient(manager, params);
}
 
開發者ID:fredsa,項目名稱:forplay,代碼行數:37,代碼來源:AndroidHttpClient.java

示例14: readURL

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public static boolean readURL(String uri, ByteArrayOutputStream bab,
		byte[] startsWith)
		throws IllegalArgumentException {

	BasicHttpParams basicHttpParams = new BasicHttpParams();
	HttpProtocolParams.setUserAgent(basicHttpParams, VUZE_REMOTE_USERAGENT);
	DefaultHttpClient httpclient = new DefaultHttpClient(basicHttpParams);

	// Prepare a request object
	HttpRequestBase httpRequest = new HttpGet(uri);

	// Execute the request
	HttpResponse response;

	try {
		response = httpclient.execute(httpRequest);

		HttpEntity entity = response.getEntity();
		if (entity != null) {

			// A Simple JSON Response Read
			InputStream is = entity.getContent();
			return readInputStreamIfStartWith(is, bab, startsWith);
		}

	} catch (Exception e) {
		VuzeEasyTracker.getInstance().logError(e);
	}

	return false;
}
 
開發者ID:vuze,項目名稱:vuze-remote-for-android,代碼行數:32,代碼來源:AndroidUtils.java

示例15: getClient

import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
private @Nonnull
HttpClient getClient(URI uri) throws InternalException, CloudException {
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new InternalException();
    }
    boolean ssl = uri.getScheme().startsWith("https");
    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    //noinspection deprecation
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(params, "");

    Properties p = ctx.getCustomProperties();

    if (p != null) {
        String proxyHost = p.getProperty("proxyHost");
        String proxyPort = p.getProperty("proxyPort");

        if (proxyHost != null) {
            int port = 0;

            if (proxyPort != null && proxyPort.length() > 0) {
                port = Integer.parseInt(proxyPort);
            }
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port, ssl ? "https" : "http"));
        }
    }
    return new DefaultHttpClient(params);
}
 
開發者ID:greese,項目名稱:dasein-cloud-virtustream,代碼行數:33,代碼來源:VirtustreamStorageMethod.java


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