use of org.apache.http.impl.client.DefaultHttpClient in project mobile-android by photo.
the class ApiBase method execute.
/**
* Execute a request to the API.
*
* @param request request to perform
* @param baseUrl the base server url
* @param consumer the oauth consumer key to sign request
* @param listener Progress Listener with callback on progress
* @param connectionTimeout the connection and socket timeout
* @return the response from the API
* @throws ClientProtocolException
* @throws IOException
*/
public ApiResponse execute(ApiRequest request, String baseUrl, OAuthConsumer consumer, ProgressListener listener, int connectionTimeout) throws ClientProtocolException, IOException {
// PoolingClientConnectionManager();
HttpParams params = new BasicHttpParams();
// set params for connection...
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
HttpConnectionParams.setSoTimeout(params, connectionTimeout);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
DefaultHttpClient httpClient = new DefaultHttpClient(params);
HttpUriRequest httpRequest = createHttpRequest(request, baseUrl, listener);
httpRequest.getParams().setBooleanParameter("http.protocol.expect-continue", false);
httpRequest.setHeader("User-Agent", "android");
httpRequest.setHeader("source", "android");
if (consumer != null) {
try {
consumer.sign(httpRequest);
} catch (Exception e) {
GuiUtils.noAlertError(TAG, "Error signing request", e);
}
} else {
TrackerUtils.trackBackgroundEvent("not_signed_request", baseUrl + request.getPath());
}
return new ApiResponse(baseUrl + request.getPath(), httpClient.execute(httpRequest));
}
use of org.apache.http.impl.client.DefaultHttpClient in project openhab1-addons by openhab.
the class HubIOStream method open.
@Override
public boolean open() {
m_client = new DefaultHttpClient();
if (m_user != null && m_pass != null) {
m_client.getCredentialsProvider().setCredentials(new AuthScope(m_host, m_port), new UsernamePasswordCredentials(m_user, m_pass));
}
HttpConnectionParams.setConnectionTimeout(m_client.getParams(), 5000);
m_in = new HubInputStream();
m_pollThread = new Thread(this);
m_pollThread.start();
m_out = new HubOutputStream();
return true;
}
use of org.apache.http.impl.client.DefaultHttpClient in project ignition by mttkay.
the class IgnitedHttp method setupHttpClient.
protected void setupHttpClient() {
BasicHttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUserAgent(httpParams, DEFAULT_HTTP_USER_AGENT);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) {
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
} else {
// used to work around a bug in Android 1.6:
// http://code.google.com/p/android/issues/detail?id=1946
// TODO: is there a less rigorous workaround for this?
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
}
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
httpClient = new DefaultHttpClient(cm, httpParams);
}
use of org.apache.http.impl.client.DefaultHttpClient in project 12306-hunter by xautlx.
the class HttpClientService method buildHttpClient.
/**
* 构建HttpClient对象
*
* @return
*/
public static HttpClient buildHttpClient() {
try {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(sslcontext);
ClientConnectionManager ccm = new DefaultHttpClient().getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 8000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 8000);
HttpClient httpclient = new DefaultHttpClient(ccm, params);
httpclient.getParams().setParameter(HTTP.USER_AGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)");
return httpclient;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
use of org.apache.http.impl.client.DefaultHttpClient in project android_frameworks_base by ResurrectionRemix.
the class CookiesTest method testCookiesAreNotLogged.
/**
* Test that we don't log potentially sensitive cookie values.
* http://b/3095990
*/
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
// enqueue an HTTP response with a cookie that will be rejected
server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
server.play();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = Logger.getLogger("org.apache.http");
StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
logger.addHandler(handler);
try {
HttpClient client = new DefaultHttpClient();
client.execute(new HttpGet(server.getUrl("/").toURI()));
handler.close();
String log = out.toString("UTF-8");
assertTrue(log, log.contains("password"));
assertTrue(log, log.contains("fake.domain"));
assertFalse(log, log.contains("secret"));
} finally {
logger.removeHandler(handler);
}
}
Aggregations