设置权限,在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. python操作mysql之pymysql

    pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持3.x版本. 本文测试python版本:2.7.11.mys ...

  2. exec 和 source的区别

    source 就是让 script 在当前 shell 内执行.而不是产生一个 sub-shell 来执行.由exec 也是让 script 在同一个行程上执行,但是原有行程则被结束了. source ...

  3. 每日一“酷”之array

    array--国定类型数据序列 array模块定义一个序列数据结构,看起来和list非常相似,只不过所有成员都必须是相同的基本类型. 1.初始化 array实例化时可以提高一个参数来描述允许哪个种数据 ...

  4. TAG的用法和用途[转]

    用一个例子来说明:一个combobox控件...一个textBox控件...一个datagridview控件!datagridview控件是连接数据库的...combobox和textBox是联合查询 ...

  5. MySQL批量杀进程

    OS: CentOS 6.3 DB:5.5.14 mysql> show processlist;+----+------+-----------+--------------------+-- ...

  6. C++中的struct和class的区别

    C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据类型的数据结构了,它已经获取了太多的功能.struct能包含成员函数吗? 能!struct能继承吗? 能!!stru ...

  7. z470 装黑苹果 10.92

    1.分两个区,一个是mac安装区,一个是镜像拷贝区. 2.把镜像压进去. 3.安装好系统. 4.把镜像区的 extent拷贝到安装好的系统盘里去. 5.安装驱动,网盘里有.还有系统也在网盘里. 6.声 ...

  8. 51nod 1257 背包问题 V3

    1257 背包问题 V3 基准时间限制:3 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 N个物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2.. ...

  9. Android Studio 单刷《第一行代码》系列 01 —— 第一战 HelloWorld

    前言(Prologue) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Android ...

  10. mvc异步表单遇到的问题

    1,mvc异步表单遇到的问题    问题:使用jqury easy ui 时提交异步数据不能请求到服务器   解决办法:经过细心调试和检测,发现jqury的加载顺序放在了easy ui之后,所以首先加 ...