dsorecdf78171 2011-12-01 16:20
浏览 18
已采纳

从Android到PHP页面发送数据

I am trying sending data from android application (with emulator) to web server (a php page) nowadays. Firstly, I had tried this program with emulator and it was working. After that, I tried this program with telephone and an exception occurred :

--> IO Exception : The operation timed out.

One part of my code :

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://10.0.2.2:90/takeDatas.php");
try {                   
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("enlem", latitude ));
    nameValuePairs.add(new BasicNameValuePair("boylam", longitude ));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    Toast.makeText(ReportLocationActivity.this, "Client protokol exception ", Toast.LENGTH_LONG).show();
} catch (IOException e) {
    Toast.makeText(ReportLocationActivity.this, "IO exception "+e.getMessage(), Toast.LENGTH_LONG).show();
}

I hope you will help me. Thanks in advance.

  • 写回答

3条回答 默认 最新

  • duanlu1908 2011-12-01 17:11
    关注

    The localhost in emulator is the emulator itself. Not sure about Windows environment, but under Linux I was able to get an access to web server on the host system from the emulator by IP 10.0.2.2 (Note: this IP is not the IP of my Linux system, but from the emulator it's accessible exactly by this IP). You can read more about emulator networking here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C