• 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);
            }
    });
  • 相关阅读:
    Hexo 与 Git 集成
    Hexo Next 调优
    【翻译】Django Channels 官方文档 -- Tutorial
    配置环境是程序员的第一步 -- Xshell 6 免费版下载安装
    一步一步理解 python web 框架,才不会从入门到放弃 -- 简单登录页面
    配置环境是程序员的第一步 -- Windows 10 下 MySQL 安装
    一步一步理解 python web 框架,才不会从入门到放弃 -- 开始使用 Django
    一步一步理解 python web 框架,才不会从入门到放弃 -- 启程出发
    生成器
    迭代器
  • 原文地址:https://www.cnblogs.com/shiningrise/p/4827840.html
Copyright © 2020-2023  润新知