I am to ask your kind help for a problem I cannot solve... I have the following code:
String https_url = "https://...";
try {
HttpsURLConnection connection = (HttpsURLConnection) new URL(https_url).openConnection();
String query = "api_key=1234&portal_id=1234&username="+username;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Length", String.valueOf(query.length()));
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
output.writeBytes(query);
output.close();
DataInputStream input = new DataInputStream( connection.getInputStream() );
String ret = "";
for( int c = input.read(); c != -1; c = input.read() ) {
ret += (char)c ;
}
input.close();
int code = connection .getResponseCode();
String message = connection .getResponseMessage();
System.out.println("Resp Code:"+code);
System.out.println("Resp Message:"+ message);
//...
This code has been running for a couple of years, and until some weeks ago, it has worked fine, then suddenly, it started to got a java.net.SocketException: Connection reset soon after the line output = new DataOutputStream(connection.getOutputStream()); This code runs into a Java web application, and it is called after the click on a button of a web page. I don't know if something has changed on server side, but the strange thing is that if I put this code into a main method of a stand alone class, export the class on an executable jar file, and launch the jar from the same environment where the web application is deployed, this code still works and I don't get any exception. Any suggestions? Thank you again Step