首页 > 代码库 > 仿12306查询火车票功能

仿12306查询火车票功能

首先感谢http://www.zuidaima.com/share/1861712958622720.html对我的帮助,我在此基础上修改了页面的显示,

先上效果吧技术分享技术分享技术分享

技术分享


public class SearchTrainController implements X509TrustManager
{

	private static String QUERY_RUL = "https://kyfw.12306.cn/otn/lcxxcx/query";

	@RequestMapping(value = http://www.mamicode.com/"searchTrain", method = RequestMethod.POST)>

接下来是我本地写的一个测试类

public class JunitTest {
	public static void main(String[] args) throws Exception {
		TrustManager[] tm = { new MyX509TrustManager() };
		SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
		sslContext.init(null, tm, new java.security.SecureRandom());
		SSLSocketFactory ssf = sslContext.getSocketFactory();
		String urlStr = "https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate=2016-06-06&from_station=BXP&to_station=WHN";
		URL url = new URL(urlStr);
		HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
		con.setSSLSocketFactory(ssf);
		InputStreamReader in = new InputStreamReader(con.getInputStream(),
				"utf-8");
		BufferedReader bfreader = new BufferedReader(in);
		StringBuffer sb = new StringBuffer();
		String line = "";
		while ((line = bfreader.readLine()) != null) {
			sb.append(line);
		}
		System.out.println(sb.toString());
	}
}


这里请求的是12306官网的,这里的请求可能会有token会话,有其他问题的,欢迎留言,主要是练习下。

网站代码:https://github.com/xiangzhihong/12306

需要源码的加群哦:278792776


仿12306查询火车票功能