首页 > 代码库 > 仿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查询火车票功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。