BlogJava
首頁(yè)
新隨筆
聯(lián)系
聚合
管理
37 Posts :: 64 Stories :: 21 Comments :: 0 Trackbacks
常用鏈接
我的隨筆
我的文章
我的評(píng)論
我的參與
最新評(píng)論
隨筆檔案
(39)
2010年6月 (1)
2009年12月 (3)
2009年11月 (1)
2009年10月 (3)
2009年9月 (16)
2009年8月 (14)
2009年7月 (1)
文章檔案
(59)
2009年11月 (2)
2009年10月 (11)
2009年9月 (15)
2009年8月 (31)
新聞檔案
(2)
2009年8月 (2)
收藏夾
(89)
DB(11)
eclipse(1)
Enterprise Eximbill
java(27)
javascript(8)
linux(4)
webservice(11)
會(huì)計(jì)(4)
工作流(3)
框架(6)
隨筆(14)
baidu
最新評(píng)論
1.?re: httpclient登錄開(kāi)心網(wǎng)[未登錄](méi)
代碼不能實(shí)現(xiàn)登錄。
--李莫愁
httpclient登錄開(kāi)心網(wǎng)
package
httpclienttest;
import
org.apache.commons.
httpclient
.Cookie;
import
org.apache.commons.
httpclient
.
HttpClient
;
import
org.apache.commons.
httpclient
.NameValuePair;
import
org.apache.commons.
httpclient
.methods.GetMethod;
import
org.apache.commons.
httpclient
.methods.PostMethod;
public
class
LoginKaixin {
private
static
final
String LOGON_SITE =
"http://www.kaixin001.com"
;
private
static
final
int
LOGON_PORT =
80
;
public
static
void
main(String[] args)
throws
Exception {
HttpClient
client =
new
HttpClient
();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
//登錄頁(yè)面
PostMethod post =
new
PostMethod(
"http://www.kaixin001.com/login/login.php"
);
NameValuePair ie =
new
NameValuePair(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)"
);
NameValuePair url =
new
NameValuePair(
"url"
,
"/home/"
);
NameValuePair username =
new
NameValuePair(
"email"
,
"xxx@163.com"
);
NameValuePair password =
new
NameValuePair(
"password"
,
"xxxxxx"
);
post.setRequestBody(
new
NameValuePair[] { ie,url,username, password});
client.executeMethod(post);
System.out.println(
"******************************登錄******************************"
);
Cookie[] cookies = client.getState().getCookies();
client.getState().addCookies(cookies);
post.releaseConnection();
System.out.println(
"******************************頁(yè)面轉(zhuǎn)向******************************"
);
String newUrl=
"http://www.kaixin001.com/home/"
;
System.out.println(
"==========Cookies============"
);
int
i=
0
;
for
(Cookie c:cookies){
System.out.println(++i+
": "
+c);
}
client.getState().addCookies(cookies);
post.releaseConnection();
GetMethod get =
new
GetMethod(newUrl);
get.setRequestHeader(
"Cookie"
, cookies.toString());
client.executeMethod(get);
String responseString = get.getResponseBodyAsString();
//登錄后首頁(yè)的內(nèi)容
System.out.println(responseString);
get.releaseConnection();
System.out.println(
"******************************組件功能******************************"
);
//"http://www.kaixin001.com/!slave/index.php", "朋友買(mǎi)賣(mài)"
//"http://www.kaixin001.com/!parking/index.php", "爭(zhēng)車(chē)位"
//"http://www.kaixin001.com/!house/index.php?_lgmode=pri", "買(mǎi)房子"
//http://www.kaixin001.com/!house/index.php?_lgmode=pri&t=49
//"http://www.kaixin001.com/!house/garden/index.php","花園"
//(1)進(jìn)入朋友買(mǎi)賣(mài)****************
System.out.println(
"******************************(1)進(jìn)入朋友買(mǎi)賣(mài)******************************"
);
String slave=
"http://www.kaixin001.com/!slave/index.php"
;
get =
new
GetMethod(slave);
get.setRequestHeader(
"Cookie"
, cookies.toString());
client.executeMethod(get);
responseString = get.getResponseBodyAsString();
System.out.println(responseString);
get.releaseConnection();
//(2)進(jìn)入爭(zhēng)車(chē)位****************
System.out.println(
"******************************(2)進(jìn)入爭(zhēng)車(chē)位******************************"
);
String parking=
"http://www.kaixin001.com/!parking/index.php"
;
get =
new
GetMethod(parking);
get.setRequestHeader(
"Cookie"
, cookies.toString());
client.executeMethod(get);
responseString = get.getResponseBodyAsString();
System.out.println(responseString);
get.releaseConnection();
//(3)進(jìn)入買(mǎi)房子****************
System.out.println(
"******************************(3)進(jìn)入買(mǎi)房子*******************************"
);
String house=
"http://www.kaixin001.com/!house/index.php?_lgmode=pri&t=49"
;
get =
new
GetMethod(house);
get.setRequestHeader(
"Cookie"
, cookies.toString());
client.executeMethod(get);
responseString = get.getResponseBodyAsString();
System.out.println(responseString);
get.releaseConnection();
//(4)進(jìn)入花園****************
System.out.println(
"******************************(4)進(jìn)入花園*******************************"
);
String garden=
"http://www.kaixin001.com/!house/garden/index.php"
;
get =
new
GetMethod(garden);
get.setRequestHeader(
"Cookie"
, cookies.toString());
client.executeMethod(get);
responseString = get.getResponseBodyAsString();
System.out.println(responseString);
get.releaseConnection();
}
}
posted on 2009-08-21 12:27
xiachang88
閱讀(3720)
評(píng)論(20)
編輯
收藏
Feedback
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-08-25 20:31
文文
開(kāi)心網(wǎng)當(dāng)然開(kāi)心喲。嘿嘿!
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-08-26 19:52
郭壇
還不錯(cuò)
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-05 15:46
雪飄飄
123
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-07 23:36
濤
sagt erg fdg
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-08 13:45
帶刺的玫瑰
我要進(jìn)去玩
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-09 22:20
王靖
請(qǐng)同意
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-09 22:21
王靖
你好請(qǐng)同意
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-15 15:45
李小林
就是想玩
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-19 10:46
王賽媛
恩恩
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)[未登錄](méi)
2009-09-21 03:47
強(qiáng)子
怎么進(jìn)去玩啊
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)[未登錄](méi)
2009-09-21 19:12
強(qiáng)子
請(qǐng)同意
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-09-28 20:36
楊新華
123
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-10-07 19:54
李娜
th/k988
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-10-27 22:05
吳燕
你好請(qǐng)同意,聽(tīng)說(shuō)很好耍
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-10-27 22:14
吳燕
聽(tīng)說(shuō)很好耍
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-11-10 18:43
匿名
代碼試了一下,登錄好像不行呀。在網(wǎng)上看了好多示例代碼,好像還沒(méi)成的
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-11-14 23:56
草爽秀
偶想玩玩
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-12-09 12:39
j88888888
不知帶好玩嗎
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)
2009-12-30 09:04
這段代碼有錯(cuò)誤
這段代碼有錯(cuò)誤
回復(fù)
更多評(píng)論
#
re: httpclient登錄開(kāi)心網(wǎng)[未登錄](méi)
2012-02-09 17:29
李莫愁
代碼不能實(shí)現(xiàn)登錄。
回復(fù)
更多評(píng)論
新用戶(hù)注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶(hù)
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
Powered by:
BlogJava
Copyright © xiachang88
主站蜘蛛池模板:
福鼎市
|
阿城市
|
沙坪坝区
|
元氏县
|
双柏县
|
兴海县
|
牙克石市
|
类乌齐县
|
普定县
|
育儿
|
铅山县
|
乡宁县
|
容城县
|
麟游县
|
色达县
|
武邑县
|
江达县
|
綦江县
|
安陆市
|
方山县
|
法库县
|
宝鸡市
|
江永县
|
社会
|
南丰县
|
万盛区
|
沅江市
|
沾益县
|
砚山县
|
墨江
|
全椒县
|
泗洪县
|
阜康市
|
荆门市
|
渑池县
|
昭觉县
|
洛扎县
|
加查县
|
卫辉市
|
河间市
|
西乡县
|