Hi,
I am trying to do a Http Post using DefaultHttpClient bundled with
Android. It works well for most of the cases but I see a strange
behavior when I click the end call button(on emulator) immediately
after I make a http call and then click on menu option to come back to
same screen which initiated the HTTP call. When I used the debugger I
found that the 3-4 minutes wait happens at the execute method call and
it becomes really worst because all the HTTP calls hang after one end
call click. It works only when I restart the emulator.
Any ideas?
Heres brief snippet of my code. I am not closing any connection
(because I use response handler so I assume the resources/connections
should get closed automatically).
private HttpResponseVO performPost(final String contentType, final
String url,
final Map<String, String> headers, final Map<String, String>
params) {
Log.d(HTTPConnectionManager.TAG, " making HTTP Post to url -
" + url);
HttpParams httpParams = new BasicHttpParams();
//hard coded temp
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
//hard coded temp
HttpConnectionParams.setSoTimeout(httpParams, 30000);
DefaultHttpClient client = new DefaultHttpClient(httpParams);
addCookiesInfo(headers);
Log.d(TAG, "!!!!!!Cookie info added......");
UrlEncodedFormEntity postData = createPostData(params);
addContentHeader(postData,headers,contentType);
addRequestHeaders(client, headers);
HttpPost method = new HttpPost(url);
method.setEntity(postData);
return execute(client, method);
}
private HttpResponseVO execute(final DefaultHttpClient client,
HttpRequestBase method) {
Log.d(HTTPConnectionManager.TAG, " execute invoked");
final ResponseHandler<HttpResponseVO> responseHandler = new
ResponseHandler<HttpResponseVO>() {
public HttpResponseVO handleResponse(HttpResponse
response) {
HttpEntity entity = response.getEntity();
HttpResponseVO resposeVO = new HttpResponseVO();
try {
storeIncomingCookies(response);
entity = response.getEntity();
String resposeString = entity==null?
null:EntityUtils.toString(entity);
Log.d(HTTPConnectionManager.TAG,resposeString);
resposeVO.setContent(resposeString);
} catch (IOException e) {
Log.d(HTTPConnectionManager.TAG,e.getMessage(),e);
}
return resposeVO;
}
};
HttpResponseVO result = null;
try {
Log.d("Payment Screen","Before making HTTP call....");
result = client.execute(method,responseHandler);
Log.d("Payment Screen","After finishing HTTP call....");
Log.d(HTTPConnectionManager.TAG, " request completed");
}catch (Exception e) {
Log.d(HTTPConnectionManager.TAG,e.getMessage(),e);
}finally{
//shutDownConnectionManager()
}
return result;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---