问题
I want to control vlc with java code and its web interface using http://localhost:8080
The problem is I don't know how exactly I must use the http requests. Here is some code I have written:
URL url = new URL("http://127.0.0.1:8080/");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
con.setRequestProperty("If-Modified-Since", "29 Oct 1999 19:43:31 GMT");
con.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
con.setRequestProperty("Content-Language", "en-US");
//DataOutputStream wr = new DataOutputStream(con.getOutputStream());
OutputStream wr = con.getOutputStream();
if (line.split(":")[1].equals("Play")) {
wr.write("requests/status.xml?command=pl_play".getBytes());
// wr.write("play".getBytes());
}
else {
wr.write("requests/status.xml?command=pl_stop".getBytes());
}
wr.flush();
//wr.close();
int status = con.getResponseCode();
System.out.println(status);
It mainly copy/paste from google. Status returns 200..
回答1:
I just had to read the response from the connection!
来源:https://stackoverflow.com/questions/22026684/control-vlc-with-requests-java