프로그램으로 웹 사이트에 로그인하려고합니다. 나는 많이 봤는데, 다른 사람들이 어떻게 든 그것을하는 방식은 나를 위해 작동하지 않습니다. 사이트에 로그인 할자바 : 웹 사이트에 로그인하는 방법
단계는 다음과 같습니다
이
는 사용자 이름 & 암호를 사용하여 쿠키 + 내용으로 PHPSESSID를 가진 후 요청을 보내는 auth.php를 요청하여 PHPSESSID를 얻을 수
나는 그 과정에서 보내고받는 패킷을보기 위해 트림 - 스위트를 사용했다.
PHPSESSID를 얻는 것은 꽤 간단합니다. 쿠키를 설정하고 게시물 요청을 보내는 것은 그리 어렵지 않지만 응답은 동일하지 않습니다.
String site = "The Site(Https://....)";
URL myUrl = new URL(site);
HttpURLConnection con = (HttpURLConnection) myUrl.openConnection();
con.setRequestMethod("GET");
Map<String, List<String>> headers = con.getHeaderFields();
//Get the PHPSESSID
for(Entry<String, List<String>> e : headers.entrySet()){
System.out.println(e.getKey() + ":" + e.getValue());
}
List<String> ff = headers.get("Set-Cookie");
String asd = ff.get(0);
String[] temp = asd.split(";");
asd = temp[0];
System.out.println(asd);
con.disconnect();
myUrl = new URL(site);
con = null;
con = (HttpURLConnection) myUrl.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Host", "The host");
con.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml");
con.setRequestProperty("Accept-Language", "de,en-US;q=0.7,en;q=0.3");
con.setRequestProperty("Referer", "https://ericsson.mareksokol.info/auth.php");
con.setRequestProperty("Connection", "close");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Cookie", asd);
con.setRequestProperty("Content-Length", "" +login.length());
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream (
con.getOutputStream());
wr.writeBytes(login); //login is just copy&pasted from burp-suite
wr.close();
System.out.println("\n");
InputStream is = con.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
StringBuilder response = new StringBuilder(); //
String line;
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
System.out.println(response);
이것은 웹 사이트에서 작업하고 로그인하는 데 처음 사용 된 것으로, 정말 감사드립니다.
당신이 다른 하나를 열보다는 설정하기 전에 당신이()'가까이'연결 변수가 null로한다고 생각합니다. –
@ cricket_007'close()'를 사용하려고 시도했지만 그런 함수가 없다. –
'con.close()'가 존재해야한다. –