So I'm trying to send a HTTPS request to my Flask application. Before, it worked successfully using just HTTP. Now, I wanted to change it to HTTPS.
But it does not work unfortunately. In my Java IDE, and my Python IDE, I get these errors:
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message (Java client side)
code 400, message Bad request version ("\x1bè\x13\x16)... and "‚ ~ˆòÎ×ý›tYê >ôeïõ?2ŸÏËðÚü$ü^d ‰ô$NªO5~EN4ë=Y8õûb~ïÁ¢˜è) bÀ,À+Ì©À0̨À/ ŸÌª £ ž ¢À$À(À#À' k j g @À.À2À-À1À&ÀÀ%À)À" HTTPStatus.BAD_REQUEST* (Flask server side)
My code for sending the request is:
URL myURL = new URL(requestUrl);
HttpsURLConnection connection = (HttpsURLConnection) myURL.openConnection();
connection.setRequestMethod("GET");
System.out.println(connection.getResponseCode());
...
Basically, I just changed my connection object to Https, and also modified the URL string to use "https" instead. It worked perfect with HTTP, and now, nothing works with HTTPS.
What do I have to do to get it working with HTTPS?
EDIT: In my Flask application, I changed app.run
to also include parameter ssl_context='adhoc'
. Now I get a different exception:
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target