【发布时间】:2010-04-06 07:20:09
【问题描述】:
我是安卓新手... 我想与服务器连接。就像我想通过 Http 连接从服务器发送数据和接收数据一样。 谁能帮助我如何做到这一点。 谁能给我提供客户端和服务器端的样本。 提前谢谢...
【问题讨论】:
我是安卓新手... 我想与服务器连接。就像我想通过 Http 连接从服务器发送数据和接收数据一样。 谁能帮助我如何做到这一点。 谁能给我提供客户端和服务器端的样本。 提前谢谢...
【问题讨论】:
我刚刚开始阅读有关 Android 的信息,但我会在这里投入两分钱。显然,Android 使用 Apache HTTPComponents 库来做你想做的事情。您应该在这里查看 HttpClient 教程: http://hc.apache.org/
希望对你有帮助。
【讨论】:
使用 Apache HTTPComponents 的快速工作示例:
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.google.com");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
String reqData = httpclient.execute(httpget, responseHandler).toString();
httpclient.getConnectionManager().shutdown();
handler.sendEmptyMessage(0);
} catch (ClientProtocolException e) {
handler.sendEmptyMessage(1);
} catch (IOException e) {
handler.sendEmptyMessage(1);
}
私有处理程序处理程序 = 新 处理程序(){ 公共无效句柄消息(消息消息){
switch (msg.what) { case 0: { // all ok, process data } break; case 1: { // show some errors } break; } } };
【讨论】: