httpclient는 로그인을 시뮬레이션합니다(js를 사용하여 쿠키 설정).
다음과 같이 코드 코드를 복사합니다.
<html>
<meta http-equiv='Content-Type' content='text/html'>
<link rel=stylesheet type=text/css href='/bbs.css'>
<script>document.cookie='utmpnum=51;path=/;domain=.' + window.location.host</script>
<script>document.cookie='utmpkey=20154732;path=/;domain=.' + window.location.host</script>
<script>document.cookie='utmpuserid=yay;path=/;domain=.' + window.location.host</script>
<meta http-equiv='새로 고침' content='0 url=/firstpage.php'>
h4ttp클라이언트 4.3:
가장 간단한 방법은 획득한 쿠키를 통해 httpclient를 사용자 정의하는 것입니다. 위의 예에 따르면 방법은 다음과 같습니다.
다음과 같이 코드 코드를 복사합니다.
CookieStore cookieStore = 새로운 BasicCookieStore();
for (int i = 0; i < 3; i++) {
문자열 이름;
문자열 값;
int flag=s.indexOf("document.cookie");
s=s.substring(flag+17);
플래그=s.indexOf('=');
name=s.substring(0, 플래그);
value=s.substring(flag+1, s.indexOf(';'));
BasicClientCookie 쿠키 = 새로운 BasicClientCookie(이름,
값);
쿠키.setVersion(0);
cookie.setDomain(".www.zju88.org"); //이 URL은 <span style="font-family: Arial, Helvetica, sans-serif;">window.location.host</의 반환 값에 해당합니다. 스팬>
cookie.setPath("/");
cookieStore.addCookie(쿠키);
}
// 매장 설정
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(쿠키스토어)
.짓다();
기계적 인조 인간:
오랫동안 검색했는데 위 방법에 해당하는 API를 찾을 수 없었습니다. 매번 방문하기 전에만 쿠키를 추가할 수 있습니다.
다음과 같이 코드 코드를 복사합니다.
문자열 쿠키="";
for (int i = 0; i < 3; i++) {
문자열 이름;
문자열 값;
int flag=s.indexOf("document.cookie");
s=s.substring(flag+17);
플래그=s.indexOf('=');
name=s.substring(0, 플래그);
value=s.substring(flag+1, s.indexOf(';'));
쿠키 +=이름 +"="+값;
만약(i!=2)
쿠키+=";";
}
/*
* 네트워크에 접속할 때마다
*/
HttpGet httpget = 새로운 HttpGet(url);
httpget.addHeader("쿠키",쿠키);
//httpclient에 이미 쿠키가 있는 경우 httpclient의 쿠키 정책을 설정해야 할 수 있습니다. 자세한 내용은 공식 API(:
HttpResponse 응답 = httpclient.execute(httpget);
ps: Java SE를 사용하는 경우 js를 실행하는 htmlunit 클래스를 사용할 수도 있습니다.