我需要读这个回显:
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/