复制代码代码如下 :
패키지 com.lkb.test;
java.util.arraylist 가져 오기;
java.util.hashmap import;
import java.util.iterator;
Java.util.list 가져 오기;
java.util.map import;
import org.apache.http.httpresponse;
import org.apache.http.client.responseHandler;
import org.apache.http.client.entity.urlencodedformentity;
import org.apache.http.client.methods.httpget;
import org.apache.http.client.methods.httppost;
import org.apache.http.impl.client.basicresponsehandler;
import org.apache.http.impl.client.defaulthttpclient;
import org.apache.http.message.basicnamevaluepair;
import org.apache.http.message.bufferedheader;
import org.apache.http.protocol.http;
import com.util.constant;
공개 클래스 JD {
// 구성 항목
개인 정적 문자열 redirecturl = "http://order.jd.com/center/list.action";
개인 정적 문자열 loginurl = "http://passport.jd.com/uc/login";
// 다음 URL을 변경하지 마십시오
개인 정적 문자열 Renrenloginurl = "https://passport.jd.com/uc/loginservice";
// httpclient는 한 세션에서 사용됩니다
개인 HTTPRPRONSE 응답;
private defaulthttpclient httpclient = new defaulthttpclient ();
공개지도 <문자열, 문자열> getParams () {
map <string, string> map = new Hashmap <String, String> ();
문자열 str = getText (loginurl);
문자열 strs1 [] = str.split ( "name =/"uuid/"value =/" ");
문자열 strs2 [] = strs1 [1] .split ( "/"/> ");
문자열 uuid = strs2 [0];
map.put ( "uuid", uuid);
System.out.println (strs2 [0]);
문자열 str3s [] = strs1 [1] .split ( "<span class =/"clr/"> </span> <입력 유형 =/"hidden/"name =/" ");
문자열 strs4 [] = str3s [1] .split ( "/>");
문자열 strs5 [] = strs4 [0] .trim (). split ( "/" ");
문자열 키 = strs5 [0];
문자열 값 = strs5 [2];
map.put (키, 값);
리턴 맵;
}
개인 부울 로그인 () {
지도 맵 = getParams ();
httppost httpost = 새로운 httppost (renrenloginurl);
// 모든 매개 변수는 웹 사이트에 게시합니다
List <CASICNAMEVALUEPAIR> NVPS = NEW ARRAYLIST <BASICNAMEVALUEPAIR> ();
nvps.add (New BasicNameValuePair ( "returnUrl", redirectUrl));
nvps.add (New BasicNameValuePair ( "loginname", constant.username);
nvps.add (New BasicNameValuePair ( "nloginpwd", constant.password));
nvps.add (New BasicNameValuePair ( "loginpwd", constant.password));
반복자 it = map.keyset (). iterator ();
while (it.hasnext ()) {
문자열 key = it.next (). toString ();
문자열 값 = map.get (key) .toString ();
nvps.add (New BasicNameValuePair (키, 값));
}
노력하다 {
httpost.setentity (new urlencodedforment.
응답 = httpclient.execute (httpost);
} catch (예외 e) {
e.printstacktrace ();
거짓을 반환합니다.
} 마지막으로 {
httpost.abort ();
}
진실을 반환하십시오.
}
개인 문자열 getRedirectLocation () {
BufferedHeader LocationHeader = (BufferedHeader) response.getFirsTheader ( "위치");
if (locationHeader == null) {
널 리턴;
}
return locationHeader.getValue ();
}
개인 문자열 getText (String RedirectLocation) {
httpget httpget = new httpget (redirectlocation);
ResponseHandler <string> responseHandler = New BasicResponseHandler ();
문자열 응답 바디 = "";
노력하다 {
responsebody = httpclient.execute (httpget, responshandler);
} catch (예외 e) {
e.printstacktrace ();
응답 바디 = null;
} 마지막으로 {
httpget.abort ();
//httpclient.getConnectionManager (). shutdown ();
}
반응 응답 바디;
}
public void printtext () {
if (login ()) {
System.out.println (getText (redirectUrl));
문자열 redirectLocation = getRedirectLocation ();
if (redirectLocation! = null) {
System.out.println (getText (redirectLocation));
}
}
}
public static void main (String [] args) {
JD Renren = New JD ();
//renren.getParams ();
Renren.printtext ();
}
}