Hi there,
I am trying to post an xml message to a sever, but I get the following exception back:
java.io.IOException: Server returned HTTP response code: 411 for URL: http://www.myurl.com/...
So, I did add connection.setRequestProperty("Content-Length", "" + encodedData.length()); to my code. Not sure why I have to do this, but anyways. Adding the above line to my code causes the following exception:
java.net.SocketException: Unexpected end of file from server
Any help would be appreciated.
Here is my code:
public String submitRequestTest(Document doc) throws MalformedURLException, IOException {
XMLOutputter outputter = new XMLOutputter();
String encodedData = URLEncoder.encode(outputter.outputString(doc));
URL url = new URL("http://www.myurl.com/api.aspx?xml=" + encodedData);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Content-Length", "" + encodedData.length());
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
String respMessage = "";
String response = reader.readLine();
while(response != null ) {
respMessage += response;
response = reader.readLine();
}
return respMessage;
}