本来是使用httpclient来get、post数据的,但是由于网站改为https,是通过加密的,本来吧是很会httpclient,但是又加入了ssl认证,所以改为java.net.URL来get/post,但是我怎么试都登陆不了:如下是我的代码 URLConnection post = (new URL("https://***********/login.aspx")).openConnection();
HttpsURLConnection huc = (HttpsURLConnection) post;
huc.setDoOutput(true);
huc.setRequestMethod("POST");
post.setRequestProperty("Content-type","text/html");
post.setRequestProperty("Cookie", cookie);
post.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
PrintWriter out = new PrintWriter(huc.getOutputStream());
out.print("lang=ch");
out.print("&username=********");
out.print("&password=********");
BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));
huc.connect(); String line = br.readLine(); while(line != null){
System.out.println(line);
line = br.readLine(); }
HttpsURLConnection huc = (HttpsURLConnection) post;
huc.setDoOutput(true);
huc.setRequestMethod("POST");
post.setRequestProperty("Content-type","text/html");
post.setRequestProperty("Cookie", cookie);
post.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
PrintWriter out = new PrintWriter(huc.getOutputStream());
out.print("lang=ch");
out.print("&username=********");
out.print("&password=********");
BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));
huc.connect(); String line = br.readLine(); while(line != null){
System.out.println(line);
line = br.readLine(); }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货