12306 java https解决方案
12306 java https
特地等强票结束才来发帖 为什么12306 init路径之后的一个js路径取不到呢 cookie也对 浏览器第二次去取也为空 求大神指点 我用的是httpclient4
------解决思路----------------------
嗯,我用的Java,也是httpclient4,那是个空白文件,直接拖到浏览器访问是不行的,用httpget方法去请求这个链接,用正则表达式匹配到那个动态js的文件名,拼接成链接,然后再去get方法请求这个!最后是可以返回文件里的内容的,然后再用正则匹配到那个key,有了key,用文件里的js加密方法就可以得到value了,只是我这一直都非法请求!
pattern = Pattern.compile("\\skey\\s?=\\s?'\\w+'");
matcher = pattern.matcher(jsText);
String key = "";
while (matcher.find()) {
key = matcher.group();
}
if (key.indexOf("'") == -1) {
Thread.sleep(1000);
getKeyPageForLogin(loginResponseText);
}
key = key.substring(key.indexOf("'")+1,key.lastIndexOf("'"));
String value = lgin.getKeyValue(key);
return new String[]{key,value};
特地等强票结束才来发帖 为什么12306 init路径之后的一个js路径取不到呢 cookie也对 浏览器第二次去取也为空 求大神指点 我用的是httpclient4
------解决思路----------------------
嗯,我用的Java,也是httpclient4,那是个空白文件,直接拖到浏览器访问是不行的,用httpget方法去请求这个链接,用正则表达式匹配到那个动态js的文件名,拼接成链接,然后再去get方法请求这个!最后是可以返回文件里的内容的,然后再用正则匹配到那个key,有了key,用文件里的js加密方法就可以得到value了,只是我这一直都非法请求!
HttpDoGetUtils.doRequestToString("https://kyfw.12306.cn/otn/login/init");
Pattern pattern = Pattern.compile("/otn/dynamicJs[^\"']+");
Matcher matcher = pattern.matcher(loginResponseText);
String jsSrc = "";
while (matcher.find()) {
jsSrc = matcher.group();
}
if (jsSrc.equals("")) {
return null;
}
String jsText = HttpDoGetUtils.doRequestToString("https://kyfw.12306.cn"+jsSrc);
pattern = Pattern.compile("\\skey\\s?=\\s?'\\w+'");
matcher = pattern.matcher(jsText);
String key = "";
while (matcher.find()) {
key = matcher.group();
}
if (key.indexOf("'") == -1) {
Thread.sleep(1000);
getKeyPageForLogin(loginResponseText);
}
key = key.substring(key.indexOf("'")+1,key.lastIndexOf("'"));
String value = lgin.getKeyValue(key);
return new String[]{key,value};