使用 JAVA/Android 和 Http 的 Chromecast 通信

Chromecast communication using JAVA/Android and Http

我正在尝试使用 Http 与 Chromecast 通信。我正在使用 this documentation about API methods and trying to execute an Youtube video on it. Following this 答案来执行 post 调用,现在我有:

@Override
public void run() {
    try {

        String urlParameters = "v=oHg5SJYRHA0";
        byte[] postData = urlParameters.getBytes();
        int postLenght = postData.length;
        //url is: new URL("http://192.168.25.99:8008/apps/YouTube")
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setInstanceFollowRedirects(true);
        urlConnection.setRequestMethod("POST");
        urlConnection.setRequestProperty("Content-Type", "application/json");
        urlConnection.setRequestProperty("Content-Length", Integer.toString(postLenght));
        urlConnection.setUseCaches(false);
        DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream());
        wr.write(postData);
        wr.flush();
        wr.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

此命令正确执行,但在 Chromecast 中没有任何反应。

我做错了什么?

有效,我只是忘了调用响应:

String responseMessage = urlConnection.getResponseMessage();

当我调用这个方法时,视频就会执行。