1. HttpFox Firefox 부가 기능 또는 Whireshark와 같은 스니퍼를 준비하십시오.
2. 사이트에 로그인 한 다음 로그인 URL, 메소드 (GET 또는 POST) 및 사용자 이름 및 비밀번호 매개 변수 이름 (로그인 페이지의 소스 코드에서 얻을 수도 있음) .
3. 사이트로 이동하여 세션 쿠키의 이름 (또는 모든 쿠키)을 가져옵니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class Tests {
public static String cookie;
public static void main(String[] args) throws MalformedURLException, IOException {
URL url = new URL("https://some_site...");
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
https.setRequestMethod("POST"); //or GET
https.addRequestProperty("usename_field_name", "username");
https.addRequestProperty("password_field_name", "password");
https.addRequestProperty("Cookie", cookie);
BufferedReader in = new BufferedReader(new InputStreamReader(https.getInputStream()));
String linea;
while ((linea = in.readLine()) != null) {
// Recover the cookie and save it in a variable.
// You must put it in other connections.
}
}
}