import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.cookie.*;
public class Test {
public Test() {
}
public void test(){
String HOST = "i61959";
HttpState initialState = new HttpState();
String domain = "monitor.google.com";
String path = "/";
Cookie mycookie = new Cookie(domain, "JSESSIONID", "E52715F1C816B6CF556486A6", path, null, false);
initialState.addCookie(mycookie);
mycookie = new Cookie(domain, "kac", "1", path, null, false);
initialState.addCookie(mycookie);
mycookie = new Cookie(domain, "cnet_7", "1", path, null, false);
initialState.addCookie(mycookie);
HttpClient client = new HttpClient();
//HttpMethod method = new GetMethod("http://i61974.google.com:80/common/monitor.gle?farm=vcomp");
HttpMethod method = new GetMethod("http://m.google.com/anitor/requestbridge.gle?http://"+ HOST +".google.com:8080/common/monitor.gle?m=serverStatus");
int statusCode = 0;
client.setState(initialState);
client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
try {
statusCode = client.executeMethod(method);
byte[] responseBody = method.getResponseBody();
System.out.println(new String(responseBody));
// Get all the cookies
Cookie[] cookies = client.getState().getCookies();
// Display the cookies
System.out.println("Present cookies: ");
for (int i = 0; i < cookies.length; i++) {
System.out.println(" - " + cookies[i].toExternalForm());
}
} catch (Exception e) {
System.out.println("IOException");
e.printStackTrace();
}finally{
method.releaseConnection();
}
}
public static void main(String[] args) {
new Test().test();
}
}
컴파일
javac -classpath http.jar:.:logging.jar:codec.jar Test.java
//아파치 로깅과 codec 패키지에 대한 dependency가 있다.
실행
java -classpath http.jar:.:logging.jar:codec.jar Test
'web' 카테고리의 다른 글
<img src="http://blogimgs.naver.com/nblog/ico_scrap01.gif" class="i_scrap" width="50" height="15" alt="본문스크랩" /> 아파치 튜닝 (0) | 2007.11.23 |
---|---|
톰캣 에러 : IOException while loading persisted sessions: java.io.EOFException (0) | 2007.11.23 |
DDos 공격의 또 다른 패턴을 잡기. (0) | 2007.10.21 |
Apache request중 abusing IP 확인하기 (0) | 2007.10.19 |
Apache request 갯수 파악하기 (0) | 2007.10.19 |