I have a problem I have been working on for the past few hours and can't seem to figure it out for the life of me.
I have an application that logs the user into my server with some data added to the httppost entity. The first time data is added to the entity everything works fine. The second time any post request is sent to the server, the client hangs until it times out.
My DefaultHttpClient is stored as a global variable in my application and loaded into my class when load_client() is called. Everything works when there are is nothing in the pairs variable, but once a pairs variable is set in setEntity a second time, the program never makes it to the "Response Received" message.
httppost = new HttpPost(format_url(base_url,controller));
logger.info("Sending Post Request");
load_client();
try {
logger.info("Setting Entity");
httppost.setEntity(new UrlEncodedFormEntity(pairs,"UTF-8"));
for(NameValuePair pair : pairs){
logger.info(pair.getName() + " : " + pair.getValue());
}
logger.info("URL Encoded");
response = httpclient.get_client().execute(httppost);
logger.info("Received response");
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
logger.info("Status: " + statusLine.toString());
is = entity.getContent();
logger.info("Content: " + is.toString());
}catch(Exception e){
logger.error("Error in http connection "+e.toString());
}
Any help would be appreciated. I really have no idea what to do at this point besides saving the old client's cookies and passing a new object to the application every time I want to make a Post request. That seems like a bad way to solve the problem.
EDIT: Here is the message after the client times out. It is never thrown when there is no data in the post request.
Error in http connection org.apache.http.NoHttpResponseException: The target server failed to respond
EDIT: Alright, I have this bug narrowed down to a single line.
DefaultHttpClient defhttpClient = new DefaultHttpClient();
logger.info("URL Encoded");
//When I pass the cookies things stop working...
//defhttpClient.setCookieStore(httpclient.get_cookies());
response = defhttpClient.execute(httppost);
logger.info("Received response");
If I make a new DefaultHttpClient and run the post request with parameters, the client can talk to the server just fine. The only problem is that I need the cookies from the old client to tell the server who the current user is. When I take the cookies from my old client and give them to my new one, the application hangs. I dont even see a request coming into my server. I think I might just have to make a new post for this one...