我现在厌倦了一段时间将服务器的响应发送到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也没有工作< / p>
答案 0 :(得分:0)
您无需指定端口号。在URL .try中使用此网址“http://10.0.2.2/php/base.php
”