程序需要用到Internet权限,所以需要在AndroidManifest.xml添加

<uses-permission android:name="android.permission.INTERNET"/>

MainActivity.java

public class MainActivity extends Activity {
private TextView info=null;
private Button Btn01=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
this.info=(TextView)super.findViewById(R.id.info);
this.Btn01=(Button)super.findViewById(R.id.Btn01);
this.Btn01.setOnClickListener(new OnClickListenerImpl()); } private class OnClickListenerImpl implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println(">>Button");
switch (v.getId()) {
case R.id.Btn01:
try {
System.out.println(">>btn01");
//URL url=new URL("http","172.17.8.28",80,"android.ashx");
URL url=new URL("http","t.sina.com",80,"/");
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
byte data[]= new byte[512];
int len=conn.getInputStream().read(data);//输入流读取
System.out.println(">>len="+len);
if(len>0){
String temp= new String(data,0,len).trim();
//flag=Boolean.parseBoolean(temp); //取出里面的bool数据
System.out.println(">>"+temp);
MainActivity.this.info.setText(temp);
}
conn.getInputStream().close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error:"+e.toString());
}
break; default:
break;
}
} }

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/Btn01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="测试" />
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> </LinearLayout>

Android Get方式发送信息的更多相关文章

  1. Android Post方式发送信息和获取URL中的图片

    需要Internet权限,AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET& ...

  2. 在android用Get方式发送http请求

    烦人的日子终于过去啦,终于又可以写博客啦,对自己的android学习做个总结,方便以后查看...... 一.在android用Get方式发送http请求,使用的是java标准类,也比较简单. 主要分以 ...

  3. Android - 向服务器发送数据(POST) - HTTPClient.

    该篇文章主要说明使用Apache提供的HTTPClient,通过post方式,向服务器发送数据.由于有些东西在 Android - 向服务器发送数据(GET)中提到过,就不再重复. 一,Android ...

  4. Android应用程序发送广播(sendBroadcast)的过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6744448 前面我们分析了Android应用程 ...

  5. Android HTTP实例 发送请求和接收响应

    Android HTTP实例 发送请求和接收响应 Android Http连接 实例:发送请求和接收响应 添加权限 首先要在manifest中加上访问网络的权限: <manifest ... & ...

  6. wireshake抓包,飞秋发送信息,python

    http://wenku.baidu.com/link?url=Xze_JY8T15pqI9mBLRpTxWF2d6MP-32xb6UwuE6tsUmitRDheJe-Ju87WlDEDBGuI5MF ...

  7. android之读取联系人信息

    联系人信息被存放在一个contacts2.db的数据库中 主要的两张表 读取联系人 读取联系人需要知道联系人内容提供者的地址,以及对应的操作对象.一般情况下操作对象是的命名方式和表明是一致的. 布局文 ...

  8. C#带cookie Post和Get方式发送数据,保持cookie

    在实际编程中,可能需要读取特定网页的信息,但很多网站需要用户登录后,才能够获取相关的页面内容,这就需要编程者先临时存储当前的cookie,在C#中可以使用CookieContainer 对象来保存登录 ...

  9. android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序

    android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序     在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity ...

随机推荐

  1. FFmpeg多媒体文件格式探测

    FFmpeg版本:3.4 在FFmpeg中,每一种文件容器格式都对应一种AVInputFormat 结构,位于源码中libavformat文件夹中.当调用avformat_open_input的时候, ...

  2. Java设计模式学习01——单例模式(转)

    原地址:http://blog.csdn.net/xu__cg/article/details/70182988 Java单例模式是一种常见且较为简单的设计模式.单例模式,顾名思义一个类仅能有一个实例 ...

  3. ServletContextListener中@Autowired失效的解决方法

    @WebListener public class ContextWebListener implements ServletContextListener { @Override public vo ...

  4. Reducing File Size

    [Reducing File Size] 1.Unity strips out unused assets. The amount of assets in your project folder d ...

  5. Xbuild

    https://github.com/zhuayi/xbuild

  6. linux系统启动过程及运行等级详解

    一.启动过程 1. 开机流程简述 1)加载BIOS硬件信息,并获取第一个启动设备的代号 2)读取第一个启动设备的MBR的引导加载程序的启动信息 3)加载核心操作系统的核心信息,核心开始解压缩,并且尝试 ...

  7. 万能头文件#include<bits/stdc++.h>

    最近在打cf时赛后翻阅别人的代码总是会发现一个陌生而奇怪的头文件#include<bits/stdc++.h> 奇怪之处就在于基本上所有的代码只要用了这个头文件就不再写其他头文件了. 百度 ...

  8. spring中添加google的guava缓存(demo)

    1.pom文件中配置 <dependencies> <dependency> <groupId>org.springframework</groupId> ...

  9. SQL Compare数据库版本比较工具

    Red Gate系列文章: Red Gate系列之一 SQL Compare 10.4.8.87 Edition 数据库比较工具 完全破解+使用教程 Red Gate系列之二 SQL Source C ...

  10. leetCode--towSum

    题目链接:https://leetcode.com/problems/two-sum/description/ 此题的意思是:给定一个target值,从给定的数组中找两个数,使得这两个数的和==tar ...