Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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
Android 为什么服务器没有返回任何东西?_Android_Http_Return - Fatal编程技术网

Android 为什么服务器没有返回任何东西?

Android 为什么服务器没有返回任何东西?,android,http,return,Android,Http,Return,我使用下面的代码从php页面www.ace.ucv.ro/android/android.php检索基本上是JSON格式的字符串 出于某种原因,无论我尝试什么,字符串结果都保持为空,其中没有存储任何内容,即使我使用特殊函数将其从InputStream转换为带有BufferedReader的字符串 我要存储的字符串称为RESULT public void connect(String url){ HttpClient client = new DefaultHttpClient(

我使用下面的代码从php页面www.ace.ucv.ro/android/android.php检索基本上是JSON格式的字符串

出于某种原因,无论我尝试什么,字符串结果都保持为空,其中没有存储任何内容,即使我使用特殊函数将其从InputStream转换为带有BufferedReader的字符串

我要存储的字符串称为RESULT

public void connect(String url){
         HttpClient client = new DefaultHttpClient();
         HttpGet httpGet = new HttpGet(url);
         HttpResponse response;

         try{
             response = client.execute(httpGet);

             Log.i("Praeda", response.getStatusLine().toString());

             HttpEntity entity = response.getEntity();

             if(entity != null){
                 result = entity.getContent().toString();
             }

             if(entity == null){
                 result = "failed";
             }
             }catch(Exception e){
             e.printStackTrace();
         }
    }

您的任何建议都会很好…

JSON响应通常是gzip的,试试这个

jsonResponse = client.execute(httpGet);
InputStream in = response.getEntity().getContent();
GZIPInputStream gin = new GZIPInputStream(in);
BufferedReader reader = new BufferedReader(new InputStreamReader(gin));
String line;
while ((line = reader.readLine()) != null) {
    jsonResponse.append(line);
}
reader.close();

您是否验证了服务器确实在发送您认为它正在发送的JSON?它生成的页面只是带有有效JSON字符串的HTML。经过测试,因此它是一个有效的JSON。问题是它没有从页面中获取任何内容:www.ace.ucv.ro/android/android可能是数据太长了吗?我会尽快尝试!非常感谢你的回答!使用了一个StringBuilder!无论如何,非常感谢你的帮助!这对我帮助很大!