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. Android调用浏览器打开网页内容
  2. Android:在WebView中获取网页源码
  3. Android在程序中打开网页
  4. Android中显示网页的多种方式
  5. Android原生代码调用H5 Web网页中的Javascript函数方法
  6. 如何通过网页打开Android APP
  7. Android中如何解析网页,获取网页中的元素内容
  8. Android WebView 远程网页 加载本地资源js/html/css
  9. Android查看网页源码与开启子线程

随机推荐

  1. android log 学习
  2. 有关Android调用服务全解析
  3. Android 之ndk开发
  4. Android的文件系统
  5. 解决Android(安卓)Studio 无法在线更新的
  6. Android实时直播,一千行java搞定不依赖jni
  7. android平台搭建详情
  8. Android之——模拟实现检测心率变化的应
  9. Android调Ajax和动态添加JS中的token(And
  10. 自定义风格和主题