Android编写访问http源代码的方法
来源:互联网 发布:ajax php 交互 编辑:程序博客网 时间:2024/06/10 00:28
Android源代码关于访问http的编写
android使用apache httpclient项目实现手机作为http客户端的调用。android使用的是最新的httpclient 4.0版本,网上很多国内的文档是3.x的,调用方式不一样。
可在activivy中直接调用httpclient做对服务器端的访问,以下是一个简单的示例代码:
package com.easymorse;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class NextActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.next_activity);
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(“http://marshal.easymorse.com/”);
try {
HttpResponse response = client.execute(get);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
for (String s = reader.readLine(); s != null; s = reader.readLine()) {
Log.v(“response”, s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
- Android编写访问http源代码的方法
- android编写访问http的源代码
- Android如何编写访问http的源代码
- android编写访问http的代码
- android编写访问http的代码
- Android HTTP请求访问的方法
- android访问http服务器的几种方法
- Android源代码的下载方法
- SIM900A访问HTTP的简单方法
- 关于 SIM900A访问HTTP的方法总结
- strcpy的源代码编写
- MFC HTTP访问方法
- Java获取任意http网页源代码的方法分享
- android 访问网络的方法
- android 访问WebService的方法
- Android 访问WebService的方法
- Android访问硬件的方法
- 关于android Http访问,上传,用了三个方法
- Python如何替换'&#'开头的html实体,比如:阳
- ExtJsGrid不能单选多行的问题
- eclipse查找一个字符串
- ListView按字母排序
- python替换指定字符
- Android编写访问http源代码的方法
- 作业1
- ABAP RTTS(转)
- Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (一) —— 总览
- 非递归实现前序遍历+中序遍历得到后序遍历的结果
- 对象序列化
- free函数与内存管理
- 深入理解OutOfMemoryError
- 自动化杂谈之我们应该以怎样的过程学习自动化