我在“DataOutputStream wr = new DataOutputStream(con.getOutputStream());”这句话中得到了异常。 “javax.net.ssl.SSLException

时间:2017-05-17 13:33:32

标签: java rest api ssl testing

我正在获得以下异常 DataOutputStream wr = new DataOutputStream(con.getOutputStream());

本声明:

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

以下是代码:

HttpURLConnection con; 
String inputLine; 
StringBuffer response=null;

try { 
  URL obj = new URL(null, url, new sun.net.www.protocol.https.Handler()); 
  con = (HttpURLConnection)obj.openConnection(); //(HttpsURLConnection)
  con.setRequestMethod(“POST”);
  con.addRequestProperty(“Content-Type”,”application/json”);

  for(Map.Entry prop : header.entrySet()) {
    con.setRequestProperty(prop.getKey(),prop.getValue());
  }

  con.setDoOutput(true); 
  DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  wr.writeBytes(postParameters); 
  wr.flush(); 
  wr.close();
} catch (Exception e) {} finally {}

0 个答案:

没有答案