When I can change Http url into Https i got this Exception
Exceptionjavax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Here is my code
String userName = ""; String password = "";
String userencode = URLEncoder.encode(userName, "utf-8");
String passencode = URLEncoder.encode(password, "utf-8");
String joint = "userName=" + userencode + "&" + "password=" + passencode;
byte[] postData = joint.toString().getBytes("UTF-8");
URL url = new URL("https:");
HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier());
HttpURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Connection", "keep-alive");
con.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
System.out.println("url load");
wr.write(joint);
wr.flush();
String inputLine;
int res=con.getResponseCode();
System.out.println(res);
BufferedReader in = new BufferedReader(new
InputStreamReader(con.getInputStream()));
StringBuffer responsedata = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
responsedata.append(inputLine);
}
System.out.println(responsedata);
}
catch (Exception e) {
System.out.println("Exception"+e);
}
Aucun commentaire:
Enregistrer un commentaire