Android:简单联网获取网页代码
设置权限,在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:简单联网获取网页代码的更多相关文章
- Windows下比较简单的获取网页源码的方法
第一个方法是使用MFC里面的 <afxinet.h> CString GetHttpFileData(CString strUrl) { CInternetSession Session( ...
- c#获取网页代码、数据、资源
//WebClient取网页源码 private string GetHtmlSource(string Url) { try { System.Net.WebClient wc = new Syst ...
- 在电脑上用chrome浏览器调试android手机里的网页代码时,无法看到本地加载的js文件
在需要调试的js文件最顶部加上代码就可以看到了: console.log('haha'); debugger;
- Python3.x获取网页源码
Python3.x获取网页源码 1,获取网页的头部信息以确定网页的编码方式: import urllib.request res = urllib.request.urlopen('http://ww ...
- JS获取整个HTML网页代码 - Android 集美软件园 - 博客频道 - CSDN.NET
JS获取整个HTML网页代码 - Android 集美软件园 - 博客频道 - CSDN.NET JS获取整个HTML网页代码 分类: Android提高 2012-01-12 23:27 1974人 ...
- c# 获取网页源代码(支持cookie),最简单代码
/// /// 获取网页源码 public static string GetHtmls(string url, string referer = "", string cooki ...
- JSON使用——获取网页返回结果是Json的代码
public String getWebData(String strUrl){ String json = null; try { URL url = new URL(strUrl); HttpUR ...
- Android BLE与终端通信(一)——Android Bluetooth基础API以及简单使用获取本地蓝牙名称地址
Android BLE与终端通信(一)--Android Bluetooth基础API以及简单使用获取本地蓝牙名称地址 Hello,工作需要,也必须开始向BLE方向学习了,公司的核心技术就是BLE终端 ...
- Python获取网页html代码
获取网页html代码: import requests res = requests.get('https://www.cnblogs.com/easyidea/p/10214559.html') r ...
随机推荐
- MVVM学习
1:MVVMLight中通过IOC注册的服务或者是类是全局的整个工程都能访问到 2:向下的结构(viem→VM→Model)也不严格是这样 3:延迟SimpleIoc的注册 4:在Navigatedt ...
- unpipc.h&unpipc.c
unpipc.h #ifndef _UNPIPC_H #define _UNPIPC_H #include <stdio.h> #include <unistd.h> #inc ...
- 微软职位内部推荐-Senior Android Developer
微软近期Open的职位: Position: Senior SDE-- Mobile Products Android/iOS/WP Senior Developer Contact Person: ...
- Interview-Increasing Sequence with Length 3.
Given an array, determine whether there are three elements A[i],A[j],A[k], such that A[i]<A[j]< ...
- linux-CentOS6.4下安装oracle11g详解
参考地址:http://dengqsintyt.iteye.com/blog/1991930
- Careercup - Facebook面试题 - 5890898499993600
2014-05-01 02:30 题目链接 原题: Given a matrix of letters and a word, check if the word is present in the ...
- html利用锚点实现定位代码实例
本章节介绍介绍一下如何利用锚点实现定位,使用锚点实现定位是html固有的功能,当然比较简单,也实现了基本的功能,但是功能相对简单一些,如果想要实现平滑的定位可以参阅jquery实现的点击页面动画方式平 ...
- PAT-乙级-1046. 划拳(15)
1046. 划拳(15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 划拳是古老中国酒文化的一个有趣的组成部分 ...
- MySQL之重设密码(忘记密码)讲解
Windows下的实际操作如下: 1.关闭正在运行的MySQL. 2.打开DOS窗口,转到mysql\bin目录. 3.输入mysqld(或mysqld-nt) --skip-grant-tables ...
- window dos 设置网络
->netsh ->pushd interface ip ->set address "本地连接" static 192.168.1.2 255.255.255. ...