Samad
Samad

Reputation: 1832

json and http client slow

I have a json parser which is parsing from a url, the app works on WiFi without problems and fast enough but on mobile network it's very slow and most of time not working.
The speed of the mobile network is good enough that whatsapp is working fast, so I don't know if the problem is related to Json parser or http client.

    // Async Task to access the web
    public String makeHttpRequest(String url, String method,
        List<NameValuePair> params) {

        HttpParams params1 = new BasicHttpParams();
        params1.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        HttpClient httpclient = new DefaultHttpClient(params1);
        HttpPost httppost = new HttpPost(url);

        try {
            httppost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse response = httpclient.execute(httppost);
            jsonResult = inputStreamToString(
                    response.getEntity().getContent()).toString();
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // return JSON String
        return jsonResult;
    }

Upvotes: 0

Views: 450

Answers (1)

Harsha Vardhan
Harsha Vardhan

Reputation: 3344

use any third party tools,which have inbuilt features to make your request fast.

AsyncHttpClient : HTTP requests happen outside the UI thread Automatic gzip response decoding support for super-fast requests

Retrofit

finally Volley Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster You can see this information from developer.android.com-training-volley

Upvotes: 1

Related Questions