国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
JAVA利用httpclient登錄開心網(wǎng)
httpclient簡單應(yīng)用,登錄開心網(wǎng)的例子


需要用到的java
commons-httpclient-3.1.jar
commons-logging.jar
log4j-1.2.15.jar
commons-codec.jar


很簡單,沒什么好說的,直接上代碼:
Java代碼
  1. package httpclienttest;   
  2.   
  3. import org.apache.commons.httpclient.Cookie;   
  4. import org.apache.commons.httpclient.HttpClient;   
  5. import org.apache.commons.httpclient.NameValuePair;   
  6. import org.apache.commons.httpclient.methods.GetMethod;   
  7. import org.apache.commons.httpclient.methods.PostMethod;   
  8.   
  9. public class LoginKaixin {   
  10.     private static final String LOGON_SITE = "http://www.kaixin001.com";   
  11.     private static final int LOGON_PORT = 80;   
  12.     public static void main(String[] args)throws Exception {   
  13.         HttpClient client = new HttpClient();   
  14.         client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);   
  15.            
  16.         //登錄頁面   
  17.         PostMethod post = new PostMethod("http://www.kaixin001.com/login/login.php");   
  18.         NameValuePair ie = new NameValuePair("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");      
  19.         NameValuePair url = new NameValuePair("url""/home/");   
  20.         NameValuePair username = new NameValuePair("email","xxx@163.com");   
  21.         NameValuePair password = new NameValuePair("password""xxxxxx");   
  22.     post.setRequestBody(new NameValuePair[] { ie,url,username, password});   
  23.         client.executeMethod(post);   
  24.         System.out.println("******************************登錄******************************");   
  25.         Cookie[] cookies = client.getState().getCookies();   
  26.         client.getState().addCookies(cookies);   
  27.         post.releaseConnection();   
  28.         System.out.println("******************************頁面轉(zhuǎn)向******************************");   
  29.         String newUrl="http://www.kaixin001.com/home/";   
  30.         System.out.println("==========Cookies============");   
  31.         int i=0;   
  32.         for(Cookie c:cookies){   
  33.             System.out.println(++i+":   "+c);   
  34.         }   
  35.         client.getState().addCookies(cookies);   
  36.         post.releaseConnection();   
  37.         GetMethod get = new GetMethod(newUrl);   
  38.         get.setRequestHeader("Cookie", cookies.toString());   
  39.         client.executeMethod(get);   
  40.         String responseString = get.getResponseBodyAsString();   
  41.         //登錄后首頁的內(nèi)容   
  42.         System.out.println(responseString);   
  43.         get.releaseConnection();   
  44.         System.out.println("******************************組件功能******************************");   
  45.         //"http://www.kaixin001.com/!slave/index.php", "朋友買賣"   
  46.         //"http://www.kaixin001.com/!parking/index.php", "爭車位"   
  47.         //"http://www.kaixin001.com/!house/index.php?_lgmode=pri", "買房子"    
  48.         //http://www.kaixin001.com/!house/index.php?_lgmode=pri&t=49   
  49.         //"http://www.kaixin001.com/!house/garden/index.php","花園"   
  50.         //(1)進入朋友買賣****************   
  51.         System.out.println("******************************(1)進入朋友買賣******************************");   
  52.         String slave="http://www.kaixin001.com/!slave/index.php";   
  53.         get = new GetMethod(slave);   
  54.         get.setRequestHeader("Cookie", cookies.toString());   
  55.         client.executeMethod(get);   
  56.         responseString = get.getResponseBodyAsString();   
  57.         System.out.println(responseString);   
  58.         get.releaseConnection();   
  59.         //(2)進入爭車位****************   
  60.         System.out.println("******************************(2)進入爭車位******************************");   
  61.         String parking="http://www.kaixin001.com/!parking/index.php";   
  62.         get = new GetMethod(parking);   
  63.         get.setRequestHeader("Cookie", cookies.toString());   
  64.         client.executeMethod(get);   
  65.         responseString = get.getResponseBodyAsString();   
  66.         System.out.println(responseString);   
  67.         get.releaseConnection();   
  68.         //(3)進入買房子****************   
  69.         System.out.println("******************************(3)進入買房子*******************************");   
  70.         String house="http://www.kaixin001.com/!house/index.php?_lgmode=pri&t=49";   
  71.         get = new GetMethod(house);   
  72.         get.setRequestHeader("Cookie", cookies.toString());   
  73.         client.executeMethod(get);   
  74.         responseString = get.getResponseBodyAsString();   
  75.         System.out.println(responseString);   
  76.         get.releaseConnection();   
  77.         //(4)進入花園****************   
  78.         System.out.println("******************************(4)進入花園*******************************");   
  79.         String garden="http://www.kaixin001.com/!house/garden/index.php";   
  80.         get = new GetMethod(garden);   
  81.         get.setRequestHeader("Cookie", cookies.toString());   
  82.         client.executeMethod(get);   
  83.         responseString = get.getResponseBodyAsString();   
  84.         System.out.println(responseString);   
  85.         get.releaseConnection();   
  86.            
  87.            
  88.     }   
  89.   
  90. }  
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
httpclient教程
用HttpClient來模擬瀏覽器GET POST
運用Apache HttpClient實作Get與Post動作 - 小嘴冰涼 - ITey...
應(yīng)用HttpClient來對付各種頑固的WEB服務(wù)器(2) [轉(zhuǎn)] - 快樂著飛舞著 - IT博客
HttpComponents入門解析
自動識別圖形驗證碼
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服