zoukankan      html  css  js  c++  java
  • 上面是获取OkhttpUtils设置获取http连接前后回调类的方法,下面才是真正使用OKhttpUtils的方法

    //get请求文本
    public void getHttpText() throws Exception {
    OkHttpUtils
    .get()
    .url("http://www.baidu.com")
    .addParams("username", "heyman")
    .addParams("password", "123")
    .id(20)
    .build()
    .execute(new MyStringCallback());
    }
    //post提交文本
    public void postHttpText(){
    String url = "http://www.baidu.com";
    OkHttpUtils
    .post()
    .url(url)
    .id(100)
    .build()
    .execute(new MyStringCallback());
    }
    //下载文件
    public void downloadFile(){
    OkHttpUtils//
    .get()//
    .url("http://vfx.mtime.cn/Video/2016/07/24/mp4/160724055620533327_480.mp4")//
    .build(http://www.amjmh.com/v/BIBRGZ_558768/)//
    .execute(new FileCallBack(Environment.getExternalStorageDirectory().getAbsolutePath(),"MyMusic.mp4"){
    @Override
    public void onError(Call call, Exception e, int i) {
    }
    @Override
    public void onResponse(File file, int i) {

    }
    @Override
    public void inProgress(float progress, long total, int id) {
    super.inProgress(progress, total, id);
    progressBar.setProgress((int) (100 * progress));
    }

    });
    }
    ?上传文件还需要一个已经编写好的Servlet的war文件来做测试,将他放入tomcat服务器的webapps目录下,启动tomcat服务器
    ————————————————

  • 相关阅读:
    [GO]使用map生成 json
    [GO]通过结构体生成json
    [GO]正则表达式
    [GO]字符串的使用
    [GO]revoer的应用
    [GO]panic的应用
    微信公众平台自定义菜单及高级接口PHP SDK
    论MySQL何时使用索引,何时不使用索引
    MYSQL explain详解
    Mysql两种存储引擎的优缺点
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11402888.html
Copyright © 2011-2022 走看看