java加载证书,访问12306的https链接
生活随笔
收集整理的這篇文章主要介紹了
java加载证书,访问12306的https链接
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
下載12306的證書,訪問12306網(wǎng)站,下載12306的證書
導(dǎo)出證書
導(dǎo)出完成后,導(dǎo)入證書
查看是否導(dǎo)入
java中加載證書
public?static?void?main(?String[]?args?){PrintWriter?out?=?null;BufferedReader?in?=?null;String?result?=?"";//設(shè)置證書System.setProperty("javax.net.ssl.trustStore","D:\\Program?Files\\Java\\jdk1.7.0_79\\bin\\12306d.keystore");??System.setProperty("javax.net.ssl.trustStorePassword",?"12306java");??try?{URL?realUrl?=?new?URL("https://kyfw.12306.cn/otn/login/loginAysnSuggest");//?打開和URL之間的連接URLConnection?conn?=?realUrl.openConnection();//?設(shè)置通用的請(qǐng)求屬性conn.setRequestProperty("accept",?"*/*");conn.setRequestProperty("connection",?"Keep-Alive");conn.setRequestProperty("user-agent","Mozilla/4.0?(compatible;?MSIE?6.0;?Windows?NT?5.1;SV1)");//?發(fā)送POST請(qǐng)求必須設(shè)置如下兩行conn.setDoOutput(true);conn.setDoInput(true);//?獲取URLConnection對(duì)象對(duì)應(yīng)的輸出流out?=?new?PrintWriter(conn.getOutputStream());//?發(fā)送請(qǐng)求參數(shù)out.print("loginUserDTO.user_name=aaa&userDTO.password=123456&randCode=182,51,19,130");//?flush輸出流的緩沖out.flush();//?定義BufferedReader輸入流來讀取URL的響應(yīng)in?=?new?BufferedReader(new?InputStreamReader(conn.getInputStream()));String?line;while?((line?=?in.readLine())?!=?null)?{result?+=?line;}System.out.println(result);}?catch?(Exception?e)?{System.out.println("發(fā)送?POST?請(qǐng)求出現(xiàn)異常!"+e);e.printStackTrace();}//使用finally塊來關(guān)閉輸出流、輸入流finally{try{if(out!=null){out.close();}if(in!=null){in.close();}}catch(IOException?ex){ex.printStackTrace();}} }本文由微兒博客原創(chuàng),博客地址:www.weare.net.cn 或者點(diǎn)擊?微兒博客
轉(zhuǎn)載于:https://blog.51cto.com/12376658/1891527
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的java加载证书,访问12306的https链接的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: timestamp类型设置默认时间
- 下一篇: bootstrap模态框使用