3

我需要阅读这个回声:

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
4

3 回答 3

3

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

response = httpClient.execute(targetHost, targetGet);
HttpEntity entity = response.getEntity();
String htmlResponse = EntityUtils.toString(entity);
于 2012-12-02T12:23:34.880 回答
1

你可以使用它的方法来HTTPEntity获取。您可以通过方法将其内容写入输出流。HTTPResponsegetEntity()writeTo(OutputStream outstream)

于 2012-12-02T12:24:04.033 回答
0

您可以通过这样做简单地获取

   HttpClient httpclient=new DefaultHttpClient(); 
   HttpPost httppost=new  HttpPost("http://192.168.10.104/android/sample.php");
   HttpResponse response = httpclient.execute(httppost);
   String str =  EntityUtils.toString(response.getEntity());
于 2013-11-26T11:22:40.053 回答