I am writing a small app that retrieves some html from a web server based on some variables in the http POST. The HTML data that comes back has a <pre> section in it with some words that are spaced out nicely using newline and tab characters but my app does not receive them. The code is as follows
HttpPost post = new HttpPost("REMOVED FOR PRIVACY");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//REMOVED FOR PRIVACY
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpClient.execute(post, httpContext);
String htmlBrief = inputStreamToString(response.getEntity().getContent()).toString();
return htmlBrief;
}
I think it might be how I am reading the response by putting it through a BufferedReader like so
private StringBuilder inputStreamToString(InputStream is) throws IOException {
int c;
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the endIndex
while ((c = rd.read()) != -1) {
total.append((char)c);
}
// Return full string
return total;
}
I thought it might be because I was reading in line by line in the buffered reader so I switched to one character at a time but it didn’t help the problem.
Any help would be greatly appreciated.
Thanks, Ben
Use Charles or Fiddler to inspect what is actually sent in the HTTP request body.
Most likely problems: