zoukankan      html  css  js  c++  java
  • xUtils

    https://github.com/wyouflf/xUtils

    HttpUtils使用方法:

    普通get方法

    HttpUtils http = new HttpUtils();
    http.send(HttpRequest.HttpMethod.GET,
        "http://www.lidroid.com",
        new RequestCallBack<String>(){
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
                testTextView.setText(current + "/" + total);
            }
    
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                textView.setText(responseInfo.result);
            }
    
            @Override
            public void onStart() {
            }
    
            @Override
            public void onFailure(HttpException error, String msg) {
            }
    });

    使用HttpUtils上传文件 或者 提交数据 到服务器(post方法)

    RequestParams params = new RequestParams();
    params.addHeader("name", "value");
    params.addQueryStringParameter("name", "value");
    
    // 只包含字符串参数时默认使用BodyParamsEntity,
    // 类似于UrlEncodedFormEntity("application/x-www-form-urlencoded")。
    params.addBodyParameter("name", "value");
    
    // 加入文件参数后默认使用MultipartEntity("multipart/form-data"),
    // 如需"multipart/related",xUtils中提供的MultipartEntity支持设置subType为"related"。
    // 使用params.setBodyEntity(httpEntity)可设置更多类型的HttpEntity(如:
    // MultipartEntity,BodyParamsEntity,FileUploadEntity,InputStreamUploadEntity,StringEntity)。
    // 例如发送json参数:params.setBodyEntity(new StringEntity(jsonStr,charset));
    params.addBodyParameter("file", new File("path"));
    ...
    
    HttpUtils http = new HttpUtils();
    http.send(HttpRequest.HttpMethod.POST,
        "uploadUrl....",
        params,
        new RequestCallBack<String>() {
    
            @Override
            public void onStart() {
                testTextView.setText("conn...");
            }
    
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
                if (isUploading) {
                    testTextView.setText("upload: " + current + "/" + total);
                } else {
                    testTextView.setText("reply: " + current + "/" + total);
                }
            }
    
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                testTextView.setText("reply: " + responseInfo.result);
            }
    
            @Override
            public void onFailure(HttpException error, String msg) {
                testTextView.setText(error.getExceptionCode() + ":" + msg);
            }
    });
  • 相关阅读:
    git各种操作:基本操作 and 多人协作 and 冲突解决
    mini-ndn0.5.0 安装教程 (避免踩坑)
    ubuntu18.04 更换镜像源
    自定义日志轮转
    linux常用命令
    Thinkphp6 + uniapp框架,接口访问跨域问题
    机器学习-主成分分析PCA与奇异值分解SVD
    机器学习-数据预处理&特征工程
    机器学习-梯度提升树(xgboost)
    github打不开怎么办
  • 原文地址:https://www.cnblogs.com/shiningrise/p/4827840.html
Copyright © 2011-2022 走看看