本文整理匯總了Java中org.apache.http.params.HttpProtocolParams.setContentCharset方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpProtocolParams.setContentCharset方法的具體用法?Java HttpProtocolParams.setContentCharset怎麽用?Java HttpProtocolParams.setContentCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.params.HttpProtocolParams
的用法示例。
在下文中一共展示了HttpProtocolParams.setContentCharset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNewHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
private static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例2: getNewHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
private static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例3: createHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
* 設置默認請求參數,並返回HttpClient
*
* @return HttpClient
*/
private HttpClient createHttpClient() {
HttpParams mDefaultHttpParams = new BasicHttpParams();
//設置連接超時
HttpConnectionParams.setConnectionTimeout(mDefaultHttpParams, 15000);
//設置請求超時
HttpConnectionParams.setSoTimeout(mDefaultHttpParams, 15000);
HttpConnectionParams.setTcpNoDelay(mDefaultHttpParams, true);
HttpProtocolParams.setVersion(mDefaultHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(mDefaultHttpParams, HTTP.UTF_8);
//持續握手
HttpProtocolParams.setUseExpectContinue(mDefaultHttpParams, true);
HttpClient mHttpClient = new DefaultHttpClient(mDefaultHttpParams);
return mHttpClient;
}
示例4: createHttpParams
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
private HttpParams createHttpParams() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUseExpectContinue(params, false);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(3));
ConnManagerParams.setMaxTotalConnections(params, 3);
ConnManagerParams.setTimeout(params, 1000);
HttpConnectionParams.setConnectionTimeout(params, 30000);
HttpConnectionParams.setSoTimeout(params, 30000);
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setTcpNoDelay(params, true);
HttpConnectionParams.setSocketBufferSize(params, 8192);
HttpClientParams.setRedirecting(params, false);
return params;
}
示例5: getNewHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
* Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore
*
* @param keyStore custom provided KeyStore instance
* @return DefaultHttpClient
*/
public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
try {
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例6: getSchemeRegistry
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public static SchemeRegistry getSchemeRegistry() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
SSLSocketFactory sf = new SSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
return registry;
} catch (Exception e) {
return null;
}
}
示例7: getNewHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/**
* Gets getUrl DefaultHttpClient which trusts getUrl set of certificates specified by the KeyStore
*
* @param keyStore custom provided KeyStore instance
* @return DefaultHttpClient
*/
public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
try {
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例8: init
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
static void init(final NetLayer lowerNetLayer)
{
try
{
HttpClientUtil.lowerNetLayer = lowerNetLayer;
final Scheme http = new Scheme("http", new NetlibSocketFactory(lowerNetLayer), 80);
supportedSchemes = new SchemeRegistry();
supportedSchemes.register(http);
// prepare parameters
final HttpParams httpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(httpParams, Util.UTF8);
HttpProtocolParams.setUseExpectContinue(httpParams, true);
// connMgr = new ThreadSafeClientConnManager(httpParams, supportedSchemes);
}
catch (final Exception e)
{
LOG.error("error during class init", e);
}
}
示例9: createHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
private DefaultHttpClient createHttpClient() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params,
HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpConnectionParams.setConnectionTimeout(params,
CONNETED_TIMEOUT * 1000);
HttpConnectionParams.setSoTimeout(params, CONNETED_TIMEOUT * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ConnManagerParams.setMaxTotalConnections(params, 4);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
schReg.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager connMgr = new ThreadSafeClientConnManager(
params, schReg);
return new DefaultHttpClient(connMgr, params);
}
示例10: createHttpParams
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
private static HttpParams createHttpParams() {
final HttpParams params = new BasicHttpParams();
// 設置是否啟用舊連接檢查,默認是開啟的。關閉這個舊連接檢查可以提高一點點性能,但是增加了I/O錯誤的風險(當服務端關閉連接時)。
// 開啟這個選項則在每次使用老的連接之前都會檢查連接是否可用,這個耗時大概在15-30ms之間
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);// 設置鏈接超時時間
HttpConnectionParams.setSoTimeout(params, TIMEOUT);// 設置socket超時時間
HttpConnectionParams.setSocketBufferSize(params, SOCKET_BUFFER_SIZE);// 設置緩存大小
HttpConnectionParams.setTcpNoDelay(params, true);// 是否不使用延遲發送(true為不延遲)
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // 設置協議版本
HttpProtocolParams.setUseExpectContinue(params, true);// 設置異常處理機製
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);// 設置編碼
HttpClientParams.setRedirecting(params, false);// 設置是否采用重定向
ConnManagerParams.setTimeout(params, TIMEOUT);// 設置超時
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(MAX_CONNECTIONS));// 多線程最大連接數
ConnManagerParams.setMaxTotalConnections(params, 10); // 多線程總連接數
return params;
}
示例11: 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;
}
示例12: getNewHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
/** generates a HTTP-Client that also supports HTTPS **/
private static DefaultHttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
BasicSSLSocketFactory sf = new BasicSSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
// setting connections types
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例13: getHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public synchronized HttpClient getHttpClient() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
// 設置連接管理器的超時
ConnManagerParams.setTimeout(params, 10000);
// 設置連接超時
HttpConnectionParams.setConnectionTimeout(params, 10000);
// 設置socket超時
HttpConnectionParams.setSoTimeout(params, 10000);
SchemeRegistry schReg = new SchemeRegistry();
// 設置https的支持
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
//設置HTTP支持
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager conManager = new ThreadSafeClientConnManager(params, schReg);
HttpClient httpClient = new DefaultHttpClient(conManager, params);
return httpClient;
}
示例14: getNewHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
private static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例15: getNewHttpClient
import org.apache.http.params.HttpProtocolParams; //導入方法依賴的package包/類
public static DefaultHttpClient getNewHttpClient(KeyStore keystore)
{
DefaultHttpClient defaulthttpclient;
try
{
MySSLSocketFactory mysslsocketfactory = new MySSLSocketFactory(keystore);
SchemeRegistry schemeregistry = new SchemeRegistry();
schemeregistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeregistry.register(new Scheme("https", mysslsocketfactory, 443));
BasicHttpParams basichttpparams = new BasicHttpParams();
HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(basichttpparams, "UTF-8");
defaulthttpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(basichttpparams, schemeregistry), basichttpparams);
}
catch (Exception exception)
{
return new DefaultHttpClient();
}
return defaulthttpclient;
}