2014-09-21 94 views
0

我有一个解析url的json解析器,该应用程序在WiFi上工作时没有问题,速度不够快,但是在移动网络上它很慢,大部分时间都不工作。
移动网络的速度足够好,whatsapp工作得很快,所以我不知道问题是否与Json解析器或http客户端相关。json和http客户端缓慢

// 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; 
    } 
+1

看到这个信息,我可以看到,你把所有这些代码我因为AsyncTask在后台运行,所以它不应该减慢你的应用。有几个很快的原因可能是,被下载的数据花费了太多时间,应用程序正在等待asynctask完成;你的数据网络很慢;你的httpServer响应速度不够快。 – 2014-09-21 03:14:57

+0

没有数据只有5 kb的网络不慢它是足够好的whatsapp工作正常 – 2014-09-21 09:17:24

回答

0

使用任何第三方工具,这些工具都具有内置功能来快速提出请求。

AsyncHttpClient: HTTP请求发生在UI线程之外 自动的gzip响应解码的超高速请求

Retrofit

终于Volley 排球是使Android的网络HTTP库的应用程序的支持更容易最重要的是,更快 你可以从developer.android.com-training-volley