I'm receiving a very strange exception trying to access a simple localhost https url.
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.
The exception:
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)
- The same http url works fine
- Accessing the https url in browser works fine
After connection.openConnection() I tried:
int responseCode = ((HttpURLConnection) conn).getResponseCode();
String msg = ((HttpURLConnection) conn).getResponseMessage();
responseCode is -1 and msg is null
HTTP Response Headers:
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)
HTTPS Reponse Headers:
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
Thanks