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服务器
    ————————————————

  • 相关阅读:
    shell文件包含
    shell输入/输出重定向
    shell流程控制
    shell echo命令(六)
    shell基本运算符(五)
    shell数组(四)
    shell传递参数-$的用法(三)
    SQL 注入 处理
    WPF 还未开始我就打算结束
    Java SDK 2.0
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11402888.html
Copyright © 2011-2022 走看看