订票系统的action请求

火车票订购系统[url] http://www.12306.cn/mormhweb/kyfw/[/url]

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.http.HttpResponse;
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.impl.client.DefaultHttpClient;

/**
 * @author zhengyisheng E-mail:[email protected]
 * @version CreateTime��2012-1-16 ����09:47:25
 * @see Class Description
 */
public class TestTicket {
	public static void main(String[] args) throws Exception {
		try{
			TrustManager easyTrustManager = new X509TrustManager() {
	            public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException {
	               
	            }

	            public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException {
	                //To change body of implemented methods use File | Settings | File Templates.
	            }

	            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
	                return new java.security.cert.X509Certificate[0];  //To change body of implemented methods use File | Settings | File Templates.
	            }
	        };

			SSLContext sslcontext = SSLContext.getInstance("TLS");
	        sslcontext.init(null, new TrustManager[]{easyTrustManager}, null);
	        SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
	        Scheme sch = new Scheme("https", sf, 443);
	    	HttpClient httpclient = new DefaultHttpClient();
			httpclient.getConnectionManager().getSchemeRegistry().register(sch);
			HttpPost httpPost = null;
			httpPost = new HttpPost("https://dynamic.12306.cn/otsweb/loginAction.do?method=init");
			HttpResponse response = httpclient.execute(httpPost);
			InputStream is = response.getEntity().getContent();
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String line = "";
			while ((line = br.readLine()) != null) {
				System.out.println(line);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	
	}
}


你可能感兴趣的:(action)