【问题标题】:HTTPUrlConnection and application/octet-stream content-type response handlingHTTPUrlConnection 和 application/octet-stream 内容类型响应处理
【发布时间】:2012-05-06 18:45:10
【问题描述】:

我正在编写一个 Android 媒体播放器,它使用 Java 的 HTTPUrlConnection 类来访问 URL。我最近收到了与以下 URL 相关的错误报告:

“http://listen.theradio.cc”

此 URL 重定向到“http://listen.theradio.cc/theradiocc.pls”,它返回 PLS 格式的播放列表。我面临的问题是我的应用程序通常会在内容类型标头字段中确定如何最好地处理 URL。我在上面发布的 URL 返回“application/octet-stream”的内容类型,它可以是任何东西。因此,我的应用程序没有尝试解析返回的播放列表,而是尝试播放 URL(显然失败了)。在这种情况下,有没有其他方法可以有效地确定 URL 返回的内容类型?我应该尝试获取 InputStream 并检查返回内容的前几行吗?

【问题讨论】:

    标签: java http media-player httpurlconnection


    【解决方案1】:

    任何东西都可以是application/octet-stream,因此它具有误导性,因为服务器不会为播放列表返回预期的内容类型。

    最好在服务器端修复。

    另外做一个HEAD请求应该可以知道URL的信息。

    http://listen.theradio.cc/theradiocc.pls 发出 curl 请求会返回以下内容。

    curl -i http://listen.theradio.cc/theradiocc.pls
    
    HTTP/1.1 200 OK
    Server: nginx
    Date: Thu, 26 Apr 2012 03:44:42 GMT
    Content-Type: application/octet-stream
    Content-Length: 111
    Last-Modified: Tue, 15 Nov 2011 23:57:04 GMT
    Connection: keep-alive
    Accept-Ranges: bytes
    
    [playlist]
    NumberOfEntries=1
    File1=http://theradio.cc:8000/trcc-stream
    Title1=TheRadio.CC
    Length1=-1
    Version=2
    

    所以事情需要修复并妥善修复!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-02
      • 2016-03-15
      • 2018-10-27
      • 1970-01-01
      • 2012-03-31
      • 2019-10-16
      • 2021-06-27
      • 1970-01-01
      相关资源
      最近更新 更多