title: "Invalid Http response" on URLConnection.getInputStream() only for https url version
body: <p>I'm receiving a very strange exception trying to access a simple localhost https url.</p>
  
  <p>My env:
  jdk1.8.0_121 on Windows, I'm running java main from Netbeans, it opens connection to https url hosted in a standalone jetty 9.4.5 configured with a self-signed cert.</p>
  
  <p>The exception:</p>
  
  <blockquote>
    <p>java.io.IOException: Invalid Http response    at
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at
    sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1926)
      at
    sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1921)
      at java.security.AccessController.doPrivileged(Native Method)   at
    sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1920)
      at
    sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1490)
      at
    sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
      at
    sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)</p>
  </blockquote>
  
  <ul>
  <li>The same http url works fine</li>
  <li>Accessing the https url in browser works fine</li>
  </ul>
  
  <p>After connection.openConnection() I tried:</p>
  
  <pre><code>int responseCode = ((HttpURLConnection) conn).getResponseCode();
  String msg = ((HttpURLConnection) conn).getResponseMessage();
  </code></pre>
  
  <p><strong>responseCode is -1 and msg is null</strong></p>
  
  <p><strong>HTTP Response Headers:</strong></p>
  
  <pre><code>Request URL:http://localhost:9393/MailProxyServer/index.jsp
  Request Method:GET
  Status Code:200 OK
  Remote Address:[::1]:9393
  Referrer Policy:no-referrer-when-downgrade
  Response Headers
  view parsed
  HTTP/1.1 200 OK
  Content-Type: text/html;charset=utf-8
  Set-Cookie: JSESSIONID=node0113il7mdp4gwq1ff3b6gg32ks90.node0;Path=/MailProxyServer
  Expires: Thu, 01 Jan 1970 00:00:00 GMT
  Content-Length: 328
  Server: Jetty(9.4.5.v20170502)
  </code></pre>
  
  <p><strong>HTTPS Reponse Headers:</strong></p>
  
  <pre><code>Request URL:https://localhost:8443/MailProxyServer/index.jsp
  Request Method:GET
  Status Code:200 
  Remote Address:[::1]:8443
  Referrer Policy:no-referrer-when-downgrade
  Response Headers
  content-type:text/html;charset=utf-8
  server:Jetty(9.4.5.v20170502)
  status:200
  </code></pre>
  
  <p>Thanks</p>