解决方案 »

  1.   

    你用电脑的浏览器IE测试一下那个URL,看看返回什么,先排除后台的原因
      

  2.   

    也就是才能取到一半的json数据,浏览器里测试是好的,能得到全部数据,我用HttpClient就只能取到接口返回数据的一半。
      

  3.   

    试一下如下代码看看:
    HttpClient hc = new DefaultHttpClient();  
        try {  
            HttpResponse ht = hc.execute(httpGet);  
            if(ht.getStatusLine().getStatusCode() == HttpStatus.SC_OK){  
                HttpEntity he = ht.getEntity();  
                InputStream is = he.getContent();  
                BufferedReader br = new BufferedReader(new InputStreamReader(is));  
                String response = "";  
                String readLine = null;  
                while((readLine =br.readLine()) != null){  
                    //response = br.readLine();  
                    response = response + readLine;  
                }  
                is.close();  
                br.close();  
                  
                //String str = EntityUtils.toString(he);  
                System.out.println("========="+response);  
                return response;  
            }else{  
                return "error";  
            }  
        } catch (ClientProtocolException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
            return "exception";  
        } catch (IOException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
            return "exception";  
        }
    另外何不考虑使用HttpUrlConnection?这个帖子对比了HttpUrlConnection和HttpClient,我觉得说的不错
    http://http://blog.csdn.net/huzgd/article/details/8712187
      

  4.   

    哥们,你给的这个函数我使用后还是不行,和原来的效果一样。为什么会这样呢?求解答啊,,,???????????public static String test(String url,List<NameValuePair> params){

    HttpParams httpParams;
    HttpClient httpClient;
    HttpPost httpRequest = new HttpPost(url);
    String response = "doPostError";
    httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 4*1000);
    HttpConnectionParams.setSoTimeout(httpParams, 6*1000);
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
    HttpClientParams.setRedirecting(httpParams, true);
    String userAgent ="Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";
    HttpProtocolParams.setUserAgent(httpParams, userAgent);
    httpClient = new DefaultHttpClient(httpParams);
    try {
    if (params != null) {
    httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    }
    httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_0);
    httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8");
    HttpResponse httpResponse = httpClient.execute(httpRequest);
    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    HttpEntity httpEntity=httpResponse.getEntity();
    InputStream is = httpEntity.getContent();  
     BufferedReader br = new BufferedReader(new InputStreamReader(is));  
                String readLine = null;  
                while((readLine =br.readLine()) != null){  
                    //response = br.readLine();  
                    response = response + readLine;  
                }  
                is.close();  
                br.close();  
    } else {
    response = "Error Response: " + httpResponse.getStatusLine().toString();//获取响应码  
    }
    } catch (ClientProtocolException e) {
    // strResult = e.getMessage().toString();
    e.printStackTrace();
    } catch (IOException e) {
    // strResult = e.getMessage().toString();
    e.printStackTrace();
    }catch (Exception e) {
    // strResult = e.getMessage().toString();
    e.printStackTrace();
    } System.out.println("strResult =" + response); return response;
    }
      

  5.   

    while((readLine =br.readLine()) != null){  是不是你的循环语句写的有问题啊,看着别扭呢HttpEntity httpEntity = new UrlEncodedFormEntity(pairs);
    httpPost.setEntity(httpEntity);
    HttpResponse httpResponse = httpClient.execute(httpPost);
    if (httpResponse.getStatusLine().getStatusCode() == 200) {
    HttpEntity entity = httpResponse.getEntity();
    return EntityUtils.toString(entity, "utf-8");
    用这个,直接转成String试试。
      

  6.   

    你看下回来的那个String,是否完整的,,,