Java を使用してインターネット上の https サイトにログインし、いくつかの情報を読みたいと考えています。私はすでにヘッダーをfirebugで見ましたが、どうにかできませんでした...
Firebug は次のように述べています。
https://service.example.net/xxx/unternehmer/login.html?login=Anmelden&loginname=xxx&password=xxx&sessionid=&sprache=de
そして、私はこのサイトを閲覧したいと思います:
https://service.example.net/xxx/unternehmer/ausgabe.html?code=PORTAL;sessionid=03112010150442
どうすればJavaでこれを行うことができますか? 私はすでに次のようなことを試しました:
import java.net.*;
import java.io.*;
import java.security.*;
import javax.net.ssl.*;
public class HTTPSClient {
public static void main(String[] args) {
int port = 443; // default https port
String host = "service.example.net";
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
// enable all the suites
String[] supported = socket.getSupportedCipherSuites();
socket.setEnabledCipherSuites(supported);
Writer out = new OutputStreamWriter(socket.getOutputStream());
// https requires the full URL in the GET line
out.write("POST https://" + host + "//xxx/unternehmer/login.html?login=Anmelden&loginname=xxx&password=xxx&sessionid=&sprache=de HTTP/1.1\r\n");
out.write("Host: " + host + "\r\n");
out.write("\r\n");
out.flush();
// read response
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
// read the header
String s;
while (!(s = in.readLine()).equals("")) {
System.out.println(s);
}
System.out.println();
// read the length
String contentLength = in.readLine();
int length = Integer.MAX_VALUE;
try {
length = Integer.parseInt(contentLength.trim(), 16);
}
catch (NumberFormatException ex) {
// This server doesn't send the content-length
// in the first line of the response body
}
System.out.println(contentLength);
int c;
int i = 0;
while ((c = in.read()) != -1 && i++ < length) {
System.out.write(c);
}
System.out.println("1.part done");
out.close();
in.close();
socket.close();
}
catch (IOException ex) {
System.err.println(ex);
}
}
}
残念ながら、それはログインでは機能しません....そして、このセッションIDを取得する場所もわかりません...毎回別のものです。あなたが私を助けてくれることを願っています。ps: 一部の関連情報を xxx に置き換えました