use of org.apache.http.params.BasicHttpParams in project XobotOS by xamarin.
the class AndroidHttpClient method newInstance.
/**
* Create a new HttpClient with reasonable defaults (which you can update).
*
* @param userAgent to report in your HTTP requests
* @param context to use for caching SSL sessions (may be null for no caching)
* @return AndroidHttpClient for you to use for all your requests.
*/
public static AndroidHttpClient newInstance(String userAgent, Context context) {
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);
HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
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);
// Use a session cache for SSL sockets
SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);
// 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", SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, sessionCache), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
// parameters without the funny call-a-static-method dance.
return new AndroidHttpClient(manager, params);
}
use of org.apache.http.params.BasicHttpParams in project XobotOS by xamarin.
the class HttpConnection method openConnection.
/**
* Opens the connection to a http server
*
* @return the opened low level connection
* @throws IOException if the connection fails for any reason.
*/
@Override
AndroidHttpClientConnection openConnection(Request req) throws IOException {
// Update the certificate info (connection not secure - set to null)
EventHandler eventHandler = req.getEventHandler();
mCertificate = null;
eventHandler.certificate(mCertificate);
AndroidHttpClientConnection conn = new AndroidHttpClientConnection();
BasicHttpParams params = new BasicHttpParams();
Socket sock = new Socket(mHost.getHostName(), mHost.getPort());
params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8192);
conn.bind(sock, params);
return conn;
}
use of org.apache.http.params.BasicHttpParams in project XobotOS by xamarin.
the class DefaultHttpClient method createHttpParams.
@Override
protected HttpParams createHttpParams() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
/*
* Android note: Send each request body without first asking the server
* whether it will be accepted. Asking first slows down the common case
* and results in "417 expectation failed" errors when a HTTP/1.0 server
* is behind a proxy. http://b/2471595
*/
HttpProtocolParams.setUseExpectContinue(params, // android-changed
false);
// determine the release version from packaged version info
final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
HttpProtocolParams.setUserAgent(params, "Apache-HttpClient/" + release + " (java 1.4)");
return params;
}
use of org.apache.http.params.BasicHttpParams in project 360-Engine-for-Android by 360.
the class PollThread method setHttpClient.
private void setHttpClient() {
int connectionTimeout = 2 * Settings.HTTP_CONNECTION_TIMEOUT;
HttpParams myHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myHttpParams, connectionTimeout);
HttpConnectionParams.setSoTimeout(myHttpParams, connectionTimeout);
mHttpClient = new DefaultHttpClient(myHttpParams);
}
use of org.apache.http.params.BasicHttpParams in project ABPlayer by winkstu.
the class HttpUtil method httpGetNoResult.
public static String httpGetNoResult(String url) {
System.out.println("httpGetNo" + url);
HttpGet httpget = new HttpGet(hostBase + url);
String strResult = "";
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
HttpClient httpclient;
try {
httpclient = new DefaultHttpClient(httpParams);
httpget.setHeader("Cookie", cookieName + "=" + cookieValue);
HttpResponse response = httpclient.execute(httpget);
System.out.println(response.getStatusLine().getStatusCode());
/*
* if(response.getStatusLine().getStatusCode() == 200){ strResult =
* EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
* System.out.println(strResult); System.out.println("getFinish"); }
*/
} catch (Exception e) {
e.printStackTrace();
strResult = "error";
}
return strResult;
}
Aggregations