android中也可以其实象普通JAVA那样,去打开远程的网页和用apache的httpclient
去获得页面内容.下面是代码,两种方法都有了:

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidTelenet extends Activity {
/** Called when the activity is first created. */
HttpUriRequest request=null;
HttpResponse resp=null;
InputStream is=null;
DefaultHttpClient client=new DefaultHttpClient();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* We will show the data we read in a TextView. */
TextView tv = new TextView(this);
/* Will be filled and displayed later. */
StringBuffer myString = new StringBuffer();
String tips=null;
try {
/* Define the URL we want to load data from. */
// URL myURL = new URL(
// "http://10.0.2.2:8085/test/Index.action");
/* Open a connection to that URL. */
// URLConnection ucon = myURL.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
// InputStream is = ucon.getInputStream();

//BufferedInputStream bis = new BufferedInputStream(is);

//if (bis.read()>0)
//{
// tips="能连上网页";
//}
//else
//{
// tips="不能连接网页";
//}
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
// ByteArrayBuffer baf = new ByteArrayBuffer(50);
//int current = 0;
//while ((current = bis.read()) != -1) {
//baf.append((byte) current);
// }
/* Convert the Bytes read to a String. */
//myString = new String(baf.toByteArray());
request=new HttpGet("http://10.0.2.2:8085/test/Index.action");
resp=client.execute(request);
HttpEntity entity = resp.getEntity();
InputStream is = entity.getContent();
BufferedReader br = new BufferedReader(
new InputStreamReader(is,"GB2312"));
String data = "";

while ((data = br.readLine()) != null) {
myString.append(data);
}
String result = myString.toString();
System.out.println("result is"+result);

System.out.println("mystring"+myString);
if (myString.indexOf("对不起,操作错误或系统维护中")>0)
{
tips="TOMCAT启动,数据库等其他异常";
}
else
{
tips="正常,无异常信息";
}

} catch (Exception e) {
/* On any Error we want to display it. */
tips= e.getMessage();
}
/* Show the String on the GUI. */
tv.setText(tips);
this.setContentView(tv);
}

}

更多相关文章

  1. JS获取整个HTML网页代码 - Android(安卓)集美软件园 - 博客频道
  2. Android(安卓)sqlite 表更新
  3. Android中使用httpclient等小结
  4. Android中使用WebView, WebChromeClient和WebViewClient加载网页
  5. Android中使用httpclient等小结
  6. android.uid.system无法读取SD卡信息
  7. Android中使用httpclient等小结
  8. Android中使用httpclient等小结
  9. Android(安卓)WebView的简单使用

随机推荐

  1. Android(安卓)学习笔记【基础扫盲篇】
  2. Android(安卓)Studio和Eclipse快捷键对比
  3. Android实现简单拨打电话功能
  4. 浅谈android的selector背景选择器
  5. Android(安卓)Intent实现页面跳转的方法
  6. Android(安卓)Handler机制之Message的发
  7. Android(安卓)布局之TableLayout
  8. Android中Activity启动模式详解
  9. android 屏幕方向切换 锁定方向
  10. Android中的几种网络请求方式详解