- 浏览: 141808 次
- 性别:
文章分类
最新评论
-
HeLinHang:
anyang763 写道 正要用,谢谢!!呵呵,不客气哈!
Android从网上下载文件 -
anyang763:
正要用,谢谢!!
Android从网上下载文件 -
HeLinHang:
48*48可以啊,我试过,没问题,16*16的我还没试过!
改变自己网站在浏览器上的图标 -
化蝶自在飞:
48*48? 太大了吧,一般好像都是16*16的
改变自己网站在浏览器上的图标
通过HttpURLConnection使用Get和Post方法发送数据
- 博客分类:
- Android
Get方法发送数据
在Get类中
HttpURLConnection conn=(HttpURLConnection)new URL(path).openConnection(); conn.setConnectTimeout(15000); conn.setRequestMethod("GET");
测试方法
new Get("http://XXXXX/WebService/index/indexindex.action?id=1&name="+URLEncoder.encode("您好","utf-8")).setGetRequest()
服务器端接收数据
HttpServletRequest request=ServletActionContext.getRequest(); System.out.println(id); System.out.println(new String(name.getBytes("ISO-8859-1"),"utf-8"));
Post方法发送数据
byte [] entity=("id=1&name="+URLEncoder.encode("您好","utf-8")).getBytes(); HttpURLConnection conn=(HttpURLConnection)new URL(path).openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");//用于指导实体数据的内容类型 conn.setRequestProperty("Content-Length",String.valueOf(entity.length));//entity为要传输的数据格式为 title=hello&time=20//可以对该数据编码 OutputStream outStream=conn.getOutputStream(); outStream.write(entity);
测试方法
new Post("http://XXXXXX/WebService/index/indexreceivePost.action").setPostRequest()
服务器端接收数据
HttpServletRequest request=ServletActionContext.getRequest(); System.out.println(id); request.setCharacterEncoding("utf-8"); System.out.println(name);
向服务器端传输xml数据
byte [] entity="<strings><id>1</id><name>hello</name></strings>".getBytes(); HttpURLConnection conn=(HttpURLConnection)new URL(path).openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-Type","text/xml; charset=UTF-8");//用于指导实体数据的内容类型 conn.setRequestProperty("Content-Length",String.valueOf(entity.length)); OutputStream outStream=conn.getOutputStream(); outStream.write(entity);
服务器端接收数据
HttpServletRequest request=ServletActionContext.getRequest(); InputStream is=request.getInputStream();
Notice:Get方式发送数据一般小于2K,如果大于2K,最好用Post方式
发表评论
-
git常用命令
2016-09-01 15:56 320git init git add 文件名 将删除或者修改的 ... -
实现带上拉和下拉刷新功能的ListView
2013-09-24 20:35 1106package com.test.test; impo ... -
实现带上拉和下拉刷新功能的ListView
2013-09-21 21:12 2package com.test.test; imp ... -
Android中SlidingView的实现
2013-04-27 07:32 1106网上找的,写的不错,感谢作者的分享! -
实现类似微博的BottomBar
2013-04-19 07:36 551主要布局: package com.test.activi ... -
Andorid中动画的使用
2013-04-18 07:48 584//使用动画 Animation myAnimat ... -
HttpPost工具类
2013-02-18 22:06 1152import java.io.IOException; ... -
解析json数据
2013-01-18 22:42 1142// 正确返回数据 // {"error_c ... -
Android ley hash的生成
2013-01-03 21:44 695确保你使用正确的密码 - 用于调试的keystore,默 ... -
Android中屏幕适配和样式主题的使用
2012-04-18 15:19 1009在res文件夹下新建和分 ... -
输入流转换成字符串
2012-04-08 00:49 906private String inputStreamTo ... -
SQLite数据库
2012-04-02 23:19 698SQLite3支持NULL,INTEGER、REAL、T ... -
ContentProvider的使用
2012-04-02 23:15 935第一步:在AndroidManifest.xml中添加 ... -
SQLite数据库的使用
2012-04-02 23:11 793第一步:继承SQLiteOpenHelper p ... -
Android中单元测试
2012-04-02 23:08 727在AndroidManifest.xml中 在< ... -
解析JSON数据
2012-03-27 23:42 752工具类:JsonUtils package cn ... -
android中SharedPerferences保存数据
2012-03-27 23:28 740SharedPerferences preference ... -
Android中的2D游戏开发
2012-03-27 22:46 1085开发思路: 第一个Activity中,设置游戏全屏,设置初 ... -
Android中向服务器发送数据的Post和Get方法
2012-01-19 18:12 2765下面是Post方法: NameValuePair ... -
android中启动服务
2011-11-20 13:21 696在Activity中 package cn.ed ...
相关推荐
HttpURLConnection的get,post和图片加载
HttpURLConnectionTest_Get_Post 里面包含HttpURLConnection实现的Get和post方法
小编刚刚用HttpURLConnection做了一个android的APP,不小心踩到了几个坑,总结下最常用的就通过HttpURLConnection来POST提交JSON数据与GET请求JSON数据。此外就是下载图片,下载图片分为显示进度与不显示进度两种。...
Android HttpUrlConnection使用方法 post and get json.
NULL 博文链接:https://zjutsoft.iteye.com/blog/1313754
并将post及get方法进行了封装,能够比较简单的调用。这里发出我自己写的源码。 在文件里面,数据的抓取为正则表达式方式抓取数据 实现的方式有。 1.根据文件中出现的字符进行抓取。 2。可以抓取前后2端的中间数据 3...
这是一个关于httpurlconnection 的网络post get 图片下载的Demo
本例子是 java 的 HttpURLConnection 使用方法,比较简单,但是涵盖了post和get两种方法,而且处理了乱码。
//使用POST提交 hc.addRequestProperty("Cookie", getSessionId()); hc.setDoOutput(true); hc.connect(); OutputStream out = hc.getOutputStream(); //参数是a=""&b=""这样拼接的一个串 out....
HttpURLConnection的demo,里面有网络请求get post 上传文件,下载文件,介绍HttpURLConnection这个类整体流程是怎样使用的,方便初学者学习
用GET还是POST 提交数据用POST 打开输入和输出流 获取上传信息 字节大小以及长度 设置请求体的类型是文本类型 获得输出流 向服务器输出数据 获得服务器响应的结果和状态码 如果 返回码等于200 得到服务器返回的输入...
httpurlconnection, http post, http get
4. 安卓系统下,AS IDE get post的使用方法,这个演示程序演示了如何用android java去访问网页,获取网页。 访问的是我的csdn主页,见程序中 streamToString getHtml HttpURLConnection conn = (HttpURLConnection) ...
HttpURLConnection的(get请求、post请求)
基于HttpURLConnection的网络访问 已封装好,一句话访问网络 可采用GET和POST两种方式访问
里面详细的写了post和get和HttpPost和HttpGet请求
httpurlconnection网络请求,get请求, post请求,封装
基于HttpURLConnection的封装http请求,进行了https校验忽略,对get和post进行了整合,更方便请求,对header以及超时的进行了可配置化处理,对返回也进行了封装,便于请求结果的处理。
Android中提供的...因此,在编程之前,应当首先明确使用的请求方法,然后再根据所使用的方式选择相应的编程方式。HttpURLConnection是继承于URLConnection类,二者都是抽象类。其对象主要通过URL的openConnectio