-1

I am trying to send a POST request from my server to my another server. It is working well on http, when executed over https, it says internal server error - Unexpected end of file from the server. Here is my code for HTTPS POST.

URL url = new URL("https://.../Action")
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
System.out.println("Connection established");
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);

//Error in the following line
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));

`

Anand
  • 693
  • 1
  • 8
  • 26

2 Answers2

1

You should use SSLsocket.and you should install the cert into you keystone.

kevinren
  • 141
  • 1
  • 1
  • 5
0

For HTTPS connection it is important to validate the SSL certificate of another server. For doing this, I used the solution posted by Shirish on the this link.

Thank you, @Indra Uprade for helping me to find the issue.

Community
  • 1
  • 1
Anand
  • 693
  • 1
  • 8
  • 26