Hallo
ich brauche ein paar Tipps zu folgender Herausforderung.
Ich möchte eine Klasse in Java Schreiben, die sich über HTTP Requestes und Reponse in meinem Router einloggt und alle Statusanfragen abliest und mir zusammengefasst präsentiert.
Nutze gerade von Apache Jakarta den HTTPRequest Client. Habe bereits ein Response erhalten,a ber mein Router bentuzt JavaScript. Wie gehe ich damit um?
Für ein paar Tipps währe ich dankbar.
Gruß,
sabelm_m
Und der Code:
ich brauche ein paar Tipps zu folgender Herausforderung.
Ich möchte eine Klasse in Java Schreiben, die sich über HTTP Requestes und Reponse in meinem Router einloggt und alle Statusanfragen abliest und mir zusammengefasst präsentiert.
Nutze gerade von Apache Jakarta den HTTPRequest Client. Habe bereits ein Response erhalten,a ber mein Router bentuzt JavaScript. Wie gehe ich damit um?
Für ein paar Tipps währe ich dankbar.
Gruß,
sabelm_m
Und der Code:
Code:
Das ist mein Code
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import java.io.*;
public class DSLStatus {
private static String url = "http://192.168.178.1/";
public static void main(String[] args) {
// Create an instance of HttpClient.
HttpClient client = new HttpClient();
// Create a method instance.
GetMethod method = new GetMethod(url);
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}
}