Hallo Experten,
ich versuche über ein Java-Programm eine HTML-GET-Anfrage auf einen entfernten host zu veranlassen, um mich anzumelden. Ich habe mich bereits vorher versucht über die URL mit vollem Connection String anzumelden, was auch funktioniert hat. Mein Programm allerdings meldet einen Fehler. Die Ausgabe lautet:
HTTP/1.1 400 Invalid URI
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Tue, 12 Feb 2008 11:20:39 GMT
Connection: close
Der Code sieht so aus (ein wenig modifiziert):
CODE:
public class Authentication
{
private static final String username=„user“;
private static final String password=„mypwd“;
public static void main(String[] args) throws MalformedURLException, IOException
{
String loginPath = „login.action?os_username=“+username+"&os_password="+password+"&os_destination=%2Fdisplay…";
System.out.println("LP= "+loginPath);
String hostname = „hostname“;
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket socket = new Socket(addr, port);
//Variablendeklaration beendet
DataOutputStream raw = new DataOutputStream(socket.getOutputStream());
Writer wr = new OutputStreamWriter(raw);
// login anfang --------------------------------------------------------------
String postdatastring=„os_username=“+username+"&os_password="+password+"";
String header = „GET " + loginPath + " HTTP/1.0\r\n“
- „Host: „+hostname+“\r\n“
- „User_Agent: Testagent\r\n“
- „Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,“ +
„video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1 \r\n“ - „Accept-Language: de,en;q=0.9\r\n“
- „Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\n“
- „Accept-Encoding: gzip, deflate, compress;q=0.9\r\n“
- „\r\n\r\n“;
wr.write(header);
wr.flush();
// Antwort auslesen
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String zeile;
while((zeile = br.readLine()) != null)
{
System.out.println(zeile);
}
}
}
Kann mir da einer von euch helfen?
Vielen Dank im Voraus.
MfG
5m