android https之一

android https之一
android https之二
android https之三
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class HttpsActivity extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main2);
		new Thread(new Runnable() {

			public void run() {
				Log.e("xx", "start");
				sendrequest();
				installCert("10.167.17.187", 8443, "changeit", "TLS");
				sendrequest();
				Log.e("xx", "end");
			}
		}).start();
	}

	private HttpPost makeHttpPost(String url) {
		HttpPost httpPost = new HttpPost(url);
		HttpParams timeParams = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(timeParams, 30 * 1000);
		HttpConnectionParams.setSoTimeout(timeParams, 30 * 1000);
		httpPost.setParams(timeParams);
		return httpPost;
	}

你可能感兴趣的:(android)