【发布时间】: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