开发者

Exception to be handled for HttpConnection

Kindly provide me the code for handling the HttpConnection or related Exceptions 开发者_运维百科& how to display that to the user.

Specifically , I would like to know how to handle TimeOut for HttpConnection & how to display that alert to the user.

Kindly provide the same code.


Here's the code

HttpPost hPost = new HttpPost(url);
StringEntity se = new StringEntity(envelope,HTTP.UTF_8);
hPost.setEntity(se);

HttpParams httpParameters = new BasicHttpParams();

// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);

// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 3000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(hPost);

HttpEntity entity = httpResponse.getEntity();
return entity; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜