use of org.apache.http.params.HttpParams in project Trello-Android by chrisHoekstra.
the class TrelloService method getHttpClient.
public HttpClient getHttpClient() {
DefaultHttpClient client = null;
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new CustomSSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
// Setting up parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
params.setBooleanParameter("http.protocol.expect-continue", true);
// Setting timeout
HttpConnectionParams.setConnectionTimeout(params, 100000);
HttpConnectionParams.setSoTimeout(params, 100000);
// Registering schemes for both HTTP and HTTPS
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
// Creating thread safe client connection manager
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
// Creating HTTP client
client = new DefaultHttpClient(ccm, params);
} catch (Exception e) {
client = new DefaultHttpClient();
}
return client;
}
use of org.apache.http.params.HttpParams in project UltimateAndroid by cymcsg.
the class HttpUtils_Deprecated method getResponseFromGetUrl.
/*
* 发送GET请求,通过URL和参数获取服务器反馈应答,通过返回的应答对象 在对数据头进行分析(如获得报文头 报文体等) params 的格式为
* key1=value1,key2=value2 url 是一个不带参数的URL params是发送get请求的参数 其将直接在url后面添加
* headinfo 是发送get请求的微博验证信息 即登陆时系统给出的合法用户验证信息
*/
public static String getResponseFromGetUrl(String url, String logininfo, String params) throws Exception {
Log.d("Chen", "url--" + url);
if (null != params && !"".equals(params)) {
url = url + "?";
String[] paramarray = params.split(",");
for (int index = 0; null != paramarray && index < paramarray.length; index++) {
if (index == 0) {
url = url + paramarray[index];
} else {
url = url + "&" + paramarray[index];
}
}
}
HttpGet httpRequest = new HttpGet(url);
httpRequest.addHeader("Cookie", logininfo);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 30000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 30000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
// DefaultHttpClient httpclient = new DefaultHttpClient();
StringBuffer sb = new StringBuffer();
try {
HttpResponse httpResponse = httpclient.execute(httpRequest);
String inputLine = "";
// Log.d("Chen","httpResponse.getStatusLine().getStatusCode()"+httpResponse.getStatusLine().getStatusCode());
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
InputStreamReader is = new InputStreamReader(httpResponse.getEntity().getContent());
BufferedReader in = new BufferedReader(is);
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
in.close();
} else if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
return "not_modify";
}
} catch (Exception e) {
e.printStackTrace();
return "net_error";
} finally {
httpclient.getConnectionManager().shutdown();
}
return sb.toString();
}
use of org.apache.http.params.HttpParams in project UltimateAndroid by cymcsg.
the class CommonHttpClient method getNewInstance.
// 每次返回同一实例
// public static synchronized HttpClient getInstance(Context mContext){
//
// if(null == singleStance){
// singleStance = getNewInstance(mContext);
// }
// return singleStance ;
// }
// 每次都返回新的HttpClient实例
public static HttpClient getNewInstance(Context mContext) {
HttpClient newInstance;
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
// 自定义三个timeout参数
/*
* 1.set a timeout for the connection manager,it defines how long we
* should wait to get a connection out of the connection pool managed by
* the connection manager
*/
ConnManagerParams.setTimeout(params, 5000);
/*
* 2.The second timeout value defines how long we should wait to make a
* connection over the network to the server on the other end
*/
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
/*
* 3.we set a socket timeout value to 4 seconds to define how long we
* should wait to get data back for our request.
*/
HttpConnectionParams.setSoTimeout(params, TIMEOUT_SOCKET);
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);
newInstance = new DefaultHttpClient(conMgr, params);
switch(checkNetworkTypeDeprecated(mContext)) {
case TYPE_CT_WAP:
{
// 通过代理解决中国移动联通GPRS中wap无法访问的问题
HttpHost proxy = new HttpHost("10.0.0.200", 80, "http");
newInstance.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Logs.v("当前网络类型为cm_cu_wap,设置代理10.0.0.200访问www");
}
break;
case TYPE_CM_CU_WAP:
{
// 通过代理解决中国移动联通GPRS中wap无法访问的问题
HttpHost proxy = new HttpHost("10.0.0.172", 80, "http");
newInstance.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Logs.v("当前网络类型为cm_cu_wap,设置代理10.0.0.172访问www");
}
break;
}
return newInstance;
}
use of org.apache.http.params.HttpParams in project Fling by entertailion.
the class HttpRequestHelper method createHttpClient.
public static DefaultHttpClient createHttpClient() {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 20000);
HttpConnectionParams.setSoTimeout(params, 20000);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
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);
return new DefaultHttpClient(conMgr, params);
}
use of org.apache.http.params.HttpParams in project Libraries-for-Android-Developers by eoecn.
the class MySSLSocketFactory method getNewHttpClient.
/**
* Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore
*
* @param keyStore
* @return
*/
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();
}
}
Aggregations