Consider me a newbie using HTML and Java. I would appreciate if you could peek at my issue and offer any suggestions. I am basically trying to do the following in order:
1) Send an HTTP request via POST
method in Java using PostMethod class.
2) Fetch result. The result I receive is in HTML format
3) The actual result contains characters like ", ;, :
etc. All the quotes are converted to entities (") in the result (htmlOutput string)
The question I have is the following. How do I avoid fetching encoded result. Is there a good way to get the result as original string that does not contain entities (")? Following is the code I use.
int statusCode = HttpStatus.SC_OK;
String scriptOutput = "";
PostMethod runnerMethod = new PostMethod(url);
try {
runnerMethod.setRequestHeader("X-Forwarded-For", LOCAL_MACHINE_IP);
runnerMethod.addParameter("script", serializedScript);
statusCode = client.executeMethod(runnerMethod);
if (statusCode != HttpStatus.SC_OK) {
scriptOutput = "HTTP Post request failed with statusCode" + statusCode +
runnerMethod.getStatusText();
throw new Exception(scriptOutput);
}
String htmlOutput = runnerMethod.getResponseBodyAsString();
scriptOutput = StringUtils.substring(htmlOutput, StringUtils.indexOf(htmlOutput,"Script:") + 8, StringUtils.indexOf(htmlOutput, "<BR/>"));
return scriptOutput;
} catch (IllegalArgumentException e) {
String errMsg = String.format("Error during Background script execution on instance. opId = %s, instanceUrl = %s, HTTP Status Code = %d, Err Message = %s",
opId, instanceUrl, statusCode, e.getMessage());
return errMsg;
}
catch (Exception e)
{
String errMsg = String.format("Error during Background script execution on instance. opId = %s, instanceUrl = %s, HTTP Status Code = %d, Err Message = %s",
opId, instanceUrl, statusCode, e.getMessage());
return errMsg;
}
finally {
runnerMethod.releaseConnection();
}
The output sample is following: