I am currently developing an android application, to submit a post request and to handle the corresponding response.
I am able to hit the post request to the corresponding URL, But when I am trying to retrive the response, I am getting half of the HTML content followed by “*Couldn’t read CGI input from STDIN.AFTER ALLOC_READ 0*“
Could anyone please help me to solve this issue.
Here are the code snippets
private void processRequest(String... params){
HttpPost post = new HttpPost("http://www.xyz.com");
HttpParams httpParams = post.getParams();
pnr = params[i];
httpParams.setParameter("param1", params[i]);
//User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1");
post.setParams(httpParams);
HttpClient client = new DefaultHttpClient();
try {
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
try {
processHtmlString(pnr, inputStreamToString(entity.getContent()).toString());
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
client.getConnectionManager().shutdown();
}
}
private String processHtmlString(String pnr, String htmlString) throws Exception{
int index = 0;
while(index < htmlString.length()){
int endIndex = (index + 3000) < (htmlString.length()) ? (index + 3000) : htmlString.length();
Log.i("HttpHelper1","HTML1 : "+htmlString.substring(index, endIndex));
index += 3000;
}
}
and the output is
………..Couldn’t read CGI input from STDIN.AFTER ALLOC_READ 0
It looks like you arent forming the request correctly (you are putting params into the same section headers go, and not in the body): try this.