Hi i am working on web service application in android.i need a class that handle all exceptions and send receive json data using URL with parameters.please help me any one with good example.
Asked
Active
Viewed 143 times
1 Answers
0
Here's a snippet from a helper class I wrote to send data via POST.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("param1", param1));
params.add(new BasicNameValuePair("param2", param2));
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.blabla.com/posterome");
httpPost.setEntity(new UrlEncodedFormEntity(params));
And to get the response...
HttpResponse httpResponse = httpClient.execute(httpPost);
Classes used in this snippet are in org.apache.http.*
package.
As for JSON, JSONObject
will suffice.
There are examples on how to use it properly everywhere on the web. Just google it.

nullpotent
- 9,162
- 1
- 31
- 42
-
Thanks AljoshaBre,can u please tell how to handle connection time out and socket time out exceptions in detail. – srinu Jul 02 '12 at 09:28
-
Does it times out on other hosts? Did you verified if its host-specific? Perhaps you're not catching the right one? Can you include a small, concise piece of code that catches the exception? And LogCat output would be useful. I'm on my way to satisfy my stomach. I will try to help you later. – nullpotent Jul 02 '12 at 09:35
-
i am getting times out on other hosts. – srinu Jul 02 '12 at 09:38
-
mHttpClient = new DefaultHttpClient(); final HttpParams params = mHttpClient.getParams(); ClientConnectionManager mgr=mHttpClient.getConnectionManager(); mHttpClient = new DefaultHttpClient( new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()),params); HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT); HttpConnectionParams.setSoTimeout(params, HTTP_SOCKET_TIME_OUT); ConnManagerParams.setTimeout(params, HTTP_TIMEOUT); – srinu Jul 02 '12 at 09:46