【问题标题】:HttpURLConnection getContentType not working for SSL connectionHttpURLConnection getContentType 不适用于 SSL 连接
【发布时间】:2014-07-23 00:55:26
【问题描述】:

对于特定的 HTTPS URL,以下 java 代码无法正确检索 Content-Type:

URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
String mimeType = connection.getContentType();

if (mimeType == null) throw new Exception("Could not detemine mimetype for remote URL."); 

但是,如果我使用 -I 卷曲 URL,我会得到以下信息:

HTTP/1.1 200 OK
Date: Wed, 23 Jul 2014 00:50:01 GMT
Server: Apache/2.4.7 (Ubuntu)
Cache-Control: max-age=0, no-cache
Connection: close
Content-Type: text/html

此外,如果我在 URL 不是 HTTPS 的情况下运行 Java 代码,getContentType 会成功检索 mime 类型。最后,Java 代码确实适用于通过 HTTPS 连接的其他服务器。

【问题讨论】:

  • 所以那个特定的 URL 有一些奇怪的地方。服务器配置。除了处理缺少的内容类型之外,您在客户端无能为力。
  • 对,但是服务器上的什么会导致这种情况?还有为什么 curl 可以看到 header 而 java.net 看不到?
  • 您是否使用过wireshark(或类似工具)来查看线路上发生了什么?您是否尝试过在获取内容类型之前获取响应代码? curl 和 java provide 是否可能在请求的 Accept 标头中提供不同的值?

标签: java http https


【解决方案1】:

该 URL 使用 AES-256 SSL,我遇到了这个问题:Java SSL DH Keypair Generation - Prime Size Error

我要么更新我的 java 要么使用充气城堡。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-16
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 2016-10-17
    • 1970-01-01
    相关资源
    最近更新 更多