本文整理汇总了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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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)");
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}