日期:2014-05-20 浏览次数:20717 次
URL url = new URL("http://192.168.1.2/vote/index.php");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//获得session信息
String session_value = urlConnection.getHeaderField("Set-Cookie");
String[] sessionId = session_value.split(";");
//保存session信息
System.out.println(sessionId[0]);
public static String sendSST2Proxy(HttpEntity entity,String proxy) throws Exception {
final HttpPost post = new HttpPost(proxy);
post.setEntity(entity);
HttpResponse httpResponse = SSLSocketFactoryEx.getNewHttpClient().execute(post);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String returnstr = IOHelper.fromIputStreamToString(httpResponse.getEntity().getContent());
Log.i(Constant.LOG_TAG, returnstr);
return returnstr;
}
return null;
}
public 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();
}
}