Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
httpclient android未满消息_Android_Http_Buffer_Httpclient_Message - Fatal编程技术网

httpclient android未满消息

httpclient android未满消息,android,http,buffer,httpclient,message,Android,Http,Buffer,Httpclient,Message,对不起我的英语。我有一个问题:当我使用httpclient时,我并没有从服务器得到完整的消息。这是我的代码: DefaultHttpClient hc = new DefaultHttpClient(); HttpPost postMethod = new HttpPost(params[0]); List<NameValuePair> nameValuePairs = ne

对不起我的英语。我有一个问题:当我使用httpclient时,我并没有从服务器得到完整的消息。这是我的代码:

                  DefaultHttpClient hc = new DefaultHttpClient();
                  HttpPost postMethod = new HttpPost(params[0]);

                  List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.length-1);
                  for(int i=1;i<params.length;i++){
                    int endF=params[i].indexOf("=");
                    nameValuePairs.add(new BasicNameValuePair(params[i].substring(0, endF),
                            params[i].substring(endF+1, params[i].length())));
                  }

                  // Url Encoding the POST parameters
                  try {
                      postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  } catch (UnsupportedEncodingException e) {
                      // writing error to Log
                      e.printStackTrace();
                  }



                try {

                    HttpResponse resp = hc.execute(postMethod);
                    BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));

                    StringBuffer sbuffer = new StringBuffer("");
                    String line = "";

                    while ((line = in.readLine()) != null) {
                        sbuffer.append(line + "\n");
                    }
                    in.close();

                    response = sbuffer.toString();

我得到的JSON甚至不在}附近。只是被剪掉了。下一部分在哪里?我怎样才能得到它呢?

试着这样做,如果它不起作用,服务器端可能会出现一些错误

final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost("http://www.yourdomain.com/service.php");

try {
  // ... Leave the post send part untouched ...

  InputStream ips  = response.getEntity().getContent();
  BufferedReader buf = new BufferedReader(new InputStreamReader(ips,"UTF-8"));
  if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
    try { throw new Exception(response.getStatusLine().getReasonPhrase()); } 
    catch (Exception e) { e.printStackTrace(); }
  }

  String s;
  StringBuilder sb = new StringBuilder();

  while (true) {
    s = buf.readLine();
    if (s == null || s.length() == 0)
      break;
    sb.append(s);
  }

  buf.close();
  ips.close();

  Log.d("yourTag", "Post response: " + sb.toString());
} 
catch (ClientProtocolException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }

大家好,欢迎来到Stack Overflow!您是否考虑过切换到HttpURLConnection?谷歌推荐姜饼和姜饼:不幸的是,它没有帮助。服务器能否在第二个http数据包中向我发送下一部分?因为服务器是vk.com,在俄罗斯,它和facebook.com一样,我不认为这是个问题。