【问题标题】:Response to android device from server php从服务器 php 对 android 设备的响应
【发布时间】:2011-05-15 15:34:09
【问题描述】:

我现在已经厌倦了一段时间,以便将响应从服务器发送到 android 并且到目前为止还没有成功...... 代码:

   try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2:80/php/base.php");
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        }catch(Exception e){
         Log.e("log_tag", "Error in http connection "+e.toString());
       } 

    StringBuilder sb;
     try{
      BufferedReader reader = new BufferedReader(new
       InputStreamReader(is,"iso-8859-1"),8);
        sb = new StringBuilder();
          sb.append(reader.readLine() + "\n");
       String line = null;
       while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
        }
       text = sb.toString();
        tv.setText(text);
         is.close();
        }

无法弄清楚什么是错的......我无法在 android 模拟器上得到响应......它只是脚本上的一个 echo 语句......我如何在设备上输出它。我也试过 json 没有工作

【问题讨论】:

  • 确保您拥有here所述的互联网权限。

标签: android response outputstream


【解决方案1】:

您无需指定端口号。在 URL 中。试试这个 url "http://10.0.2.2/php/base.php"

【讨论】:

    猜你喜欢
    • 2021-10-27
    • 2014-10-13
    • 2013-11-06
    • 2016-05-06
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 2015-03-05
    相关资源
    最近更新 更多