设置权限,在AndroidManifest.xml加入

<uses-permission android:name="android.permission.INTERNET"/>
public class MainActivity extends Activity {
private EditText address;
private Button getbutton;
private TextView text; @Override
protected void onCreate(Bundle savedInstanceState) {
//版本4.0后需加这个,不然就报错android.os.NetworkOnMainThreadException
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
.penaltyLog().penaltyDeath().build());
//
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
//初始化 address = (EditText) findViewById(R.id.address);
getbutton = (Button) findViewById(R.id.getbutton);
text = (TextView) findViewById(R.id.text); getbutton.setOnClickListener(new Button.OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
String url = address.getText().toString();
getPDAServerData(url);
}
}); } public void getPDAServerData(String url) {
HttpClient client = new DefaultHttpClient();
HttpPost request; try { request = new HttpPost(url); //调用HttpClient对象的execute(HttpUriRequest request)发送请求,返回一个HttpResponse
HttpResponse response = client.execute(request); //返回响应码为200
if (response.getStatusLine().getStatusCode() == 200) { //从响应中获取消息实体
HttpEntity entity = response.getEntity();
if (entity != null) {
String out = EntityUtils.toString(entity);
text.setText(out);
}
} } catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } }

实例下载>>>>>>>>>

Android:简单联网获取网页代码的更多相关文章

  1. Windows下比较简单的获取网页源码的方法

    第一个方法是使用MFC里面的 <afxinet.h> CString GetHttpFileData(CString strUrl) { CInternetSession Session( ...

  2. c#获取网页代码、数据、资源

    //WebClient取网页源码 private string GetHtmlSource(string Url) { try { System.Net.WebClient wc = new Syst ...

  3. 在电脑上用chrome浏览器调试android手机里的网页代码时,无法看到本地加载的js文件

    在需要调试的js文件最顶部加上代码就可以看到了: console.log('haha'); debugger;

  4. Python3.x获取网页源码

    Python3.x获取网页源码 1,获取网页的头部信息以确定网页的编码方式: import urllib.request res = urllib.request.urlopen('http://ww ...

  5. JS获取整个HTML网页代码 - Android 集美软件园 - 博客频道 - CSDN.NET

    JS获取整个HTML网页代码 - Android 集美软件园 - 博客频道 - CSDN.NET JS获取整个HTML网页代码 分类: Android提高 2012-01-12 23:27 1974人 ...

  6. c# 获取网页源代码(支持cookie),最简单代码

    /// /// 获取网页源码 public static string GetHtmls(string url, string referer = "", string cooki ...

  7. JSON使用——获取网页返回结果是Json的代码

    public String getWebData(String strUrl){ String json = null; try { URL url = new URL(strUrl); HttpUR ...

  8. Android BLE与终端通信(一)——Android Bluetooth基础API以及简单使用获取本地蓝牙名称地址

    Android BLE与终端通信(一)--Android Bluetooth基础API以及简单使用获取本地蓝牙名称地址 Hello,工作需要,也必须开始向BLE方向学习了,公司的核心技术就是BLE终端 ...

  9. Python获取网页html代码

    获取网页html代码: import requests res = requests.get('https://www.cnblogs.com/easyidea/p/10214559.html') r ...

随机推荐

  1. jquery批量控制form禁用的代码

    jquery批量控制form禁用的代码. 代码: <script type="text/javascript" src="/jquery/jquery-1.8.2. ...

  2. 修改Win7远程桌面端口

    Win7与XP不同,在开启远程桌面修改端口后是无法直接访问的,原因是还未修改远程桌面在防火墙入站规则中的端口号. 修改远程桌面端口: [HKEY_LOCAL_MACHINE/SYSTEM/Curren ...

  3. hdu 5451 Best Solver 矩阵循环群+矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=5451 题意:给定x    求解 思路: 由斐波那契数列的两种表示方法, 之后可以转化为 线性表示 F[n] = ...

  4. centos 6.4 apache开启gzip方法

    系统概况,主机CentOS6.4  Apache2.4 php5.3.6 mysql5.5 开始:首先得确认apache是否已经加载了mod_deflate模块 1.httpd -M 在结果中查看是否 ...

  5. 结构体,公用体,枚举类型的sizeof

    1)枚举类enum型空间计算 enum只是定义了一个常量集合,里面没有“元素”,而枚举类型是当做int来存储的,所以枚举类型的sizeof值都为4 enum color(red,pink,white, ...

  6. When to use Class.isInstance() & when to use instanceof operator?

    I think the official documentation gives you the answer to this one (albeit in a fairly nonspecific ...

  7. 论坛类应用双Tableview翻页效果实现

    作为一名篮球爱好者,经常使用虎扑体育,虎扑体育应用最核心的部分就是其论坛功能,无论哪个版块,论坛都是其核心,而其论坛部分的实现又别具一格,它以两个tableview的形式翻页滚动显示,而不是常见的那种 ...

  8. 怎样开启SQL数据库服务

    使用数据库时开启服务是需要的,我给大家具体介绍几种方式开启SQL Sever 服务.这几种我都用图文的形式用三个开启方式给你展示,对于不会开启服务的朋友可以学习下,这些前提是你的电脑安装了SQL数据库 ...

  9. hadoop历史服务器配置问题

    作者:sdjnzqr 出处:http://www.cnblogs.com/sdjnzqr/ 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须在文章中给出原文连接 ...

  10. 【模板】Big-Step-Giant-Step 大步小步

    求一个 的最小整数解 bsgs 当h是质数的时候使用 extbsgs 不满足上面那种情况的时候 具体参见http://tonyfang.is-programmer.com/posts/178997.h ...