android - 在 Android 中将 PHP echo 读入字符串

标签 android

我需要读这个回显:

http://wee.co.il/Ski/weatherScript.php?op=3

转换成字符串,我试过:

class RetreiveEcho extends AsyncTask<String, Void, String> 
{
    private static final String TAG = "Her";

    @Override
    protected String doInBackground(String... params) {

        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://wee.co.il/Ski/weatherScript.php?op=3");

        Log.d(TAG, "Hello!");
        try {
            HttpResponse response = httpclient.execute(httppost);
            Log.d(TAG, ""+response);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }
}

目前我只在我的日志中看到:

 org.apache.http.message.BasicHttpResponse@4132e5a8

最佳答案

代码中的 HTTPResponse 对象是保存响应的 java 对象。它不是一个普通的字符串。因此,打印对象会产生给定的日志输出。要访问 php echo,您可以尝试以下代码:

response = httpClient.execute(targetHost, targetGet);
HttpEntity entity = response.getEntity();
String htmlResponse = EntityUtils.toString(entity);

关于android - 在 Android 中将 PHP echo 读入字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13669214/

相关文章:

android - 在基于服务的类中设置监听器

android - 图像未完全显示在 Horizo​​ntalScrollView 中

android - 多播 - 没有这样的设备

java - 如何显示这种引用“...”?

java - 如何解决这个 java.lang.RuntimeException?

android - 类转换异常 : ApiException cannot be cast to RevolvableApiException after updating location library to 21 version

android - 如何在 ConstraintLayout 中垂直或水平放置 View ?

PHP用RSA解密加密密码,Android看到一些垃圾数据加上解密后的真实数据

java - 如何区分不同的wifi网络?

android - Cordova 构建会删除所有应用程序文件