【问题标题】:Unable to load data from server on webservice with php and android无法使用 php 和 android 从 web 服务上的服务器加载数据
【发布时间】:2014-07-17 11:35:16
【问题描述】:

当我包含 function.php 文件时,Android 无法获取数据。但是当我删除当前 php 文件中的文件包含代码时,Android 会获取数据。如何解决此错误。我想在 function.php 文件中使用一些函数。所以我必须使用包含代码调用function.php。

不知道是android还是php的问题?

我的 PHP 版本:5.3.10 阿帕奇版本:2.2.21

我的安卓代码:

 HttpClient client = new DefaultHttpClient();
        HttpConnectionParams.setConnectionTimeout(client.getParams(), 500000);
        HttpConnectionParams.setSoTimeout(client.getParams(), 500000);
        HttpUriRequest request = new HttpGet(CategoryAPI);
        HttpResponse response = client.execute(request);
        InputStream atomInputStream = response.getEntity().getContent();
        BufferedReader in = new BufferedReader(new InputStreamReader(atomInputStream));

        String line;
        String str = "";
        while ((line = in.readLine()) != null){
            str += line;
        }

        // parse json data and store into arraylist variables
        JSONObject json = new JSONObject(str);
        JSONArray data = json.getJSONArray("data");

        for (int i = 0; i < data.length(); i++) {
            JSONObject object = data.getJSONObject(i); 

            JSONObject feed = object.getJSONObject("Feeds"); 

            FeedItem.allFeedItemsList.add(new FeedItem(Integer.parseInt(feed.getString("id")), feed.getString("name"), feed.getString("post_img"), feed.getString("post_description"), feed.getString("userimage"), feed.getString("post_date"), feed.getString("post_title")));   
        }

谁能帮忙?????????

【问题讨论】:

  • 它不在 android 端..请检查你的 php 代码
  • @NightCrawler...好的,谢谢。我检查了很多次,但我得到的数据不包括function.php。但使用时无法获取数据。那怎么办,请....
  • 对不起@thet 我不是一个 php 人.. 你的 android 代码对我来说似乎很好,这就是为什么我告诉你这是一个 php 问题..
  • @NightCrawler 感谢您的回复(评论)

标签: php android web-services api httpresponse


【解决方案1】:

现在我可以通过在 ANSI 中编码来解决我的错误。由于我用 UTF-8 编码,android 无法加载。现在,它很好。谢谢.......

【讨论】:

    【解决方案2】:

    尝试使用这个库:-https://github.com/Abhishekpalodath/FetchServerUtil-Android.git。 您还可以使用它加载实时数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      • 1970-01-01
      • 2015-08-09
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多