【发布时间】:2012-12-15 17:47:23
【问题描述】:
我想测试我的 Android 应用是否可以在没有 JSON 的情况下从 php 页面成功获取响应。 php 只包含echo "hello";,但我没有吐槽它。我能找到的最接近的解决方案是,我试图将其中的一些部分放入我的代码中:How can I view the string sent from httppost?
我的代码如下(更新):
public void onClick(View v) {
Thread t = new Thread() {
@Override
public void run() {
Log.i("Threaded", "Inside thread!!!");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.10/fyp/test.php");
try {
HttpResponse response = httpclient.execute(httppost);
InputStream content = response.getEntity().getContent();
Log.i("Connect", content.toString());
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = buffer.readLine()) != null) {
sb.append(line + "\n");
}
Log.i("Connect", sb.toString());
handler.post(new Runnable() {
public void run() {
showToastMessage("hello");
}
});
} catch (Exception e) {
Log.e("Connect", "Fail");
e.printStackTrace();
}
}
};
}
线程似乎没有运行,Log.i("Threaded", "Inside thread!!!"); 行没有显示在 LogCat 中,我做错了哪一部分?注意:类中已经声明了handler。
【问题讨论】:
-
如果可以,请发布堆栈跟踪,以便我们知道错误是什么
-
“错误”是我不能敬酒“你好”,我猜答案是@Nicklas。