android有三种网络接口:
1.通过java 接口
try{
//定义url
Url url = new URL("http://www.baidu.com");
//打开链接连接
HttpURLConnextion http = (HttpURLConnection)url.open();
int nrc = http.getResponseCode();//
if(nrc == HttpURKConnection.HTTP_OK){
//获得数据
InputStream is = http.getInputStream();
//处理数据.....
}
}catch(Exception e){}
2.apache接口
try{
//使用DefaultHttpClient默认属性
HttpClient hc = new DefaultHttpClient();
//HttpGet实例
HttpGet get = new HttpGet("http://www.baidu.com");
//执行get方式
HttpResponse rp = hc.execute(get);
if(rp.getStatusLine().getStatusCode()==HtppStatus.SC_OK){
InputStream is = rp.getEntity().getCOntent();
//处理数据
}
}carch(Exception e){}
3.android网络接口
try{
//Ip地址
InetAddress ia = InetAddress.getByName("192.168.1.110");
//端口
Socket client = new Socket(ia,61203,true);
//获取数据
InputStream in = client.getInputStream();
OutputStream out = client.getOptputStream();
//处理数据
out.close();
in.close();
client.close();
}catch(Exception e){}