




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验指导(五)网络访问与服务一、实验目的本次实验的目的是让大家通过一些小例子,学习和掌握Android网络访问方法。二、实验要求1、 了解手机WEB网站访问的编程方法2、 通过网络进行数据访问三、实验步骤项目界面:使用HttpClient来提交或者获取server端的数据 。Get:Post1、创建项目新建一个Android工程,目录结构如下图:2、添加布局文件修改main.xml布局文件,如下 3、创建Activitypublic class slide8_3 extends Activity public String myhttpget(String url) throws Exception String out = null;try HttpClient client = new DefaultHttpClient();HttpGet request = new HttpGet(url);HttpResponse response = client.execute(request);out = EntityUtils.toString(response.getEntity(); catch (IOException e) e.printStackTrace();return out;public String myhttppost(String url, String name, String value)throws Exception String out = null;try HttpClient client = new DefaultHttpClient();HttpPost request = new HttpPost(url);List postParameters = new ArrayList();postParameters.add(new BasicNameValuePair(name, value);UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);request.setEntity(formEntity);HttpResponse response = client.execute(request);out = EntityUtils.toString(response.getEntity(); catch (IOException e) e.printStackTrace();return out;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.main);final TextView textView = (TextView) findViewById(R.id.TextView01);final EditText editText = (EditText) findViewById(R.id.editText1);final EditText name = (EditText) findViewById(R.id.editText2);final EditText value = (EditText) findViewById(R.id.editText3);Button btn = (Button) this.findViewById(R.id.Button1);btn.setOnClickListener(new Button.OnClickListener() public void onClick(View v) try textView.setText(myhttpget(editText.getText().toString()+ ? + name.getText().toString() + =+ value.getText().toString(); catch (Exception e) e.printStackTrace(););Button btn2 = (Button) this.findViewById(R.id.Button2);btn2.setOnClickListener(new Button.OnClickListener() public void onClick(View v) try textView.setText(myhttppost(editText.getText().toString(),name.getText().toString(), value.getText().toString(); c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 建筑方案设计-沈福熙
- 消费金融风险控制体系研究报告
- 数字版权保护加密策略研究
- 车身控制模块V-CAN电路故障诊断与检测教学设计-2025-2026学年中职专业课-电动汽车控制系统故障诊断与检修-新能源汽车运用与维修-交通运输大类
- 2025至2030中国图像采集卡行业产业运行态势及投资规划深度研究报告
- 医院职称晋升流程及管理办法
- 2025至2030中国索利伏汀行业项目调研及市场前景预测评估报告
- 微型企业税务筹划与风险管控手册
- 特步营销策划方案前言
- 2025至2030中国汽车声学材料行业发展趋势分析与未来投资战略咨询研究报告
- 2025年新城区行政中心建设项目社会稳定风险评估与治理策略报告
- 广东省公安厅机场公安局招聘警务辅助人员考试真题2024
- 2025年村级后备干部选拔考试题库及答案
- 《大数的认识》 单元测试(含答案)2025-2026学年四年级上册数学人教版
- 2025-2026学年北京版(2024)小学体育与健康三年级全一册《知情绪 善表达》教学设计
- 产前筛查考试题及答案
- 2025年事业编时政题目及答案
- 2025年川教版(2024)小学信息科技三年级(上册)教学设计及反思(附目录P118)
- 酒店住宿水单模板-可修改
- 防水堵漏施工合同
- 工程类助理工程师评审表(共12页)
评论
0/150
提交评论