我正在尝试使用我的 j2me 应用程序下载 Rails 服务器提供的音频文件。这是我的一段代码:
try {
connection = (HttpConnection) Connector.open("http://host.com/user/getaudio/65/");
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty("User-Agent", "Profile/MIDP-2.1 Configuration/CLDC-1.1");
System.out.println("HTTP Response: " + connection.getResponseMessage()); // OK
System.out.println("HTTP ResponseCode: " + connection.getResponseCode()); // 200
System.out.println("HTTP ResponseLength: " + connection.getLength()); // -1
connection.close();
} catch (IOException e) {
e.printStackTrace();
}
HTTP 响应正常,代码:200。一切正常,但 connection.getLength() 返回 -1。我已经意识到该文件是通过 Content-Disposition 标头附加的。我知道如何使用 connection.getHeaderField() 来实现它,但接下来呢?有可能以某种方式达到它吗?
问候,彼得