http请求后获得所需要的是字符串的时候

                URL url=new URL(strurl);
try {
HttpURLConnection conn=(HttpURLConnection) url.openConnection();
conn.setConnectTimeout(10*1000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
int size=conn.getContentLength();
InputStream input=conn.getInputStream();
InputStreamReader inputreader=new InputStreamReader(input);
BufferedReader bufferreader=new BufferedReader(inputreader);
StringBuffer strbuffer=new StringBuffer();
byte [] b=new byte [1024];
String temp;
while((temp=bufferreader.readLine())!=null){
strbuffer.append(b);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

文件下载

 /**

     * 文件下载

     */

    private void downloadFile()

    {

        try {

            URL u = new URL(url);

            URLConnection conn = u.openConnection();

            conn.connect();

            InputStream is = conn.getInputStream();

            fileSize = conn.getContentLength();

            if(fileSize<1||is==null)

            {

                sendMessage(DOWNLOAD_ERROR);

            }else{

                sendMessage(DOWNLOAD_PREPARE);

                FileOutputStream fos = new FileOutputStream(getPath());

                byte[] bytes = new byte[1024];

                int len = -1;

                while((len = is.read(bytes))!=-1)

                {

                    fos.write(bytes, 0, len);

                    downloadSize+=len;

                    sendMessage(DOWNLOAD_WORK);

                }

                sendMessage(DOWNLOAD_OK);

                is.close();

                fos.close();

            }

        } catch (Exception e) {

            sendMessage(DOWNLOAD_ERROR);

            e.printStackTrace();

        }

    }

    /**

     * 得到文件的保存路径

     * @return

     * @throws IOException

     */

    private String getPath() throws IOException

    {

        String path = FileUtil.setMkdir(this)+File.separator+url.substring(url.lastIndexOf("/")+1);

        return path;

    }

BitMap对象

URL  url = new URL(params);

HttpURLConnection conn  = (HttpURLConnection)url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream inputStream=conn.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream

http的应用httpurlconnection--------1的更多相关文章

  1. HttpUrlConnection 基础使用

    From https://developer.android.com/reference/java/net/HttpURLConnection.html HttpUrlConnection: A UR ...

  2. HttpURLConnection类

    导语 java.net.HttpURLConnectin类是URLConnection类的抽象子类.它在处理协议为HTTP的URL时特别有效.具体而言,它通过它可以获取和设置请求方法,确定是否重定向, ...

  3. android 之HttpURLConnection的post,get方式请求数据

    get方式和post方式的区别: 1.请求的URL地址不同: post:"http://xx:8081//servlet/LoginServlet" get:http://xxx: ...

  4. Android 6.0 使用HttpURLConnection 使用Get提交遇到405等问题。

    HttpURLConnection 在调用connection.setDoOutput(true)之后会自动把提交方式改为POST.然后调用方法的时候有可能会出现这种情况 在调用get的时候设置为co ...

  5. android——HttpUrlConnection

    前面了解了下服务端和客户端的相关知识 ,那么他们是通过什么来进行进行连接的呢? Android可以用HttpURLConnection或HttpClient接口来开发http程序.在Android 上 ...

  6. HttpUrlConnection发送url请求(后台springmvc)

    1.HttpURLConnection发送url请求 public class JavaRequest { private static final String BASE_URL = "h ...

  7. Android探索之HttpURLConnection网络请求

    前言: 最近一直想着学习一下比较好的开源网络框架okhttp,想着学习之前还是先总结一下Android原生提供的网络请求.之前一直在使用HttpClient,但是android 6.0(api 23) ...

  8. HttpUrlConnection

    •HttpUrlConnection是java的标准类,继承UrlConnection类,二者都是抽象类.其对象主要通过URL的                                     ...

  9. Android使用HttpURLConnection通过POST方式发送java序列化对象

    使用HttpURLConnection类不仅可以向WebService发送字符串,还可以发送序列化的java对象,实现Android手机和服务器之间的数据交互. Android端代码: public ...

  10. java http工具类和HttpUrlConnection上传文件分析

    利用java中的HttpUrlConnection上传文件,我们其实只要知道Http协议上传文件的标准格式.那么就可以用任何一门语言来模拟浏览器上传文件.下面有几篇文章从http协议入手介绍了java ...

随机推荐

  1. 【转】Styling And Animating SVGs With CSS

    原文转自:http://www.smashingmagazine.com/2014/11/03/styling-and-animating-svgs-with-css/?utm_source=CSS- ...

  2. input屏蔽历史记录

    设置input 的扩展属性 autocomplete为off即可 <input type="text" autocomplete="off" />

  3. 使用 CSS 去掉 iPhone 网页上按钮的超大圆角默认样式

    使用 iPhone 上的浏览器去浏览网页的时候,按钮总是显示超大圆角的样式,显得超级恶心,但是我们自己定义 border-radius 为 0 也无法去除这个圆角,经过搜索发现这是 webikt 内核 ...

  4. foreach属性-动态-mybatis中使用map类型参数,其中key为列名,value为列值

    http://zhangxiong0301.iteye.com/blog/2242723 最近有个需求,就是使用mybatis时,向mysql中插入数据,其参数为map类型,map里面的key为列名, ...

  5. Javascript操作Cookie的脚本 — CookieHelper

    var HttpCookie = function(name, value, expires, path, domain) { if (name) this.Name = name; if (valu ...

  6. 用Sublime Text搭建简易IDE编写Verilog代码

    前言 Verilog是一种硬件描述语言(HDL),该语言在Windows上有集成开发环境可以使用,如ModelSim,但ModelSim的编辑器不太好用因此笔者萌生了用Sublime Text3来编写 ...

  7. oracle之压缩表

    oracle压缩数据的处理基于数据库块,本质是通过消除在数据库中的重复数据来实现空间节约. 具体做法: 比较数据块中包含的所有字段或记录,其中重复的数据只在位于数据块开始部分的记号表(Symbol T ...

  8. Spring mvc创建的web项目,如何获知其web的项目名称,访问具体的链接地址?

    Spring mvc创建的web项目,如何获知其web的项目名称,访问具体的链接地址? 访问URL:  http://localhost:8090/firstapp/login 在eclipse集成的 ...

  9. memcached 常用命令及使用说明

    1.启动Memcache 常用参数 -p <num> 设置TCP端口号(默认设置为: ) -U <num> UDP监听端口(默认: , 时关闭) -l <ip_addr& ...

  10. < 独立项目 - 文本挖掘 > - 2016/11/13 第二更 - <Python环境准备>

    < 独立项目 -  文本挖掘 > 项目立项的相关背景介绍,TODO方向. 一.Ubuntu环境配置 主机系统:Windows 7 SP1  64位操作系统 | i5-4210 CPU | ...