Java 向https发送post请求

Java 向https发送post请求,java,post,https,Java,Post,Https,我需要向https地址发送post请求。我有一个功能,发送后消息当前,但我似乎不能使其工作的https public static String serverCall(String link, String data){ HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null;

我需要向https地址发送post请求。我有一个功能,发送后消息当前,但我似乎不能使其工作的https

public static String serverCall(String link, String data){
     HttpURLConnection connection;
     OutputStreamWriter request = null;

         URL url = null;
         String response = null;
         String parameters = data;

         try
         {
             url = new URL(link);
             connection = (HttpURLConnection) url.openConnection();
             connection.setDoOutput(true);
             connection.setRequestProperty("Content-Type", "text/xml");
             connection.setRequestMethod("POST"); 

             request = new OutputStreamWriter(connection.getOutputStream());
             request.write(parameters);
             request.flush();
             request.close();
             String line = "";
             InputStreamReader isr = new InputStreamReader(connection.getInputStream());
             BufferedReader reader = new BufferedReader(isr);
             StringBuilder sb = new StringBuilder();
             while ((line = reader.readLine()) != null)
             {
                 sb.append(line + "\n");
             }
             // Response from server after  process will be stored in response variable.
             response = sb.toString();

             isr.close();
             reader.close();

         }
         catch(IOException e)
         {
             // Error
         }

         return response;
}


我已尝试使用HttpsURLConnection而不是HttpURLConnection,但我的服务器仍然返回空值。

您应该调用
connect()


您的服务器支持SSL吗?不显示正在运行的代码。显示不工作的代码。您是如何尝试使用HttpsURLConnection的?您在哪里从服务器获取空值?给出传递给方法和构造函数的参数的示例。该代码不适用于https。。。我尝试将HttpURLConnection替换为HttpsURLConnectionworks,无论是否使用http,都无助于解决我的https连接问题。。。
....
connection.setRequestMethod("POST");
connection.connect();
....