zoukankan      html  css  js  c++  java
  • Xutils请求服务器json数据与下载文件

    String code_url = "https://ic.snssdk.com/user/mobile/send_code/v2/";
                                HttpUtils httpUtils = new HttpUtils();
    //网址 RequestParams
    params = new RequestParams(); params.addBodyParameter("type", "1");// 必填 params.addBodyParameter("mobile",shoujihao );// 必填

    httpUtils.send(HttpMethod.POST, code_url, params, new RequestCallBack<String>() { @Override public void onStart() { // TODO Auto-generated method stub super.onStart(); Log.i("TAG", "请求开始"); } @Override public void onFailure(HttpException arg0, String arg1) { Log.i("TAG", "发送验证码请求失败: " + arg1); Toast.makeText(PhoneZhuCe.this, "发送验证码请求失败: "+ arg1, 0).show(); } @Override public void onSuccess(ResponseInfo<String> arg0) { Log.i("TAG", "发送验证码请求成功: " + arg0.result); String s=arg0.result;
    Gson gson
    =new Gson(); Loginphone fromJson = gson.fromJson(s, Loginphone.class); String message = fromJson.getMessage(); if(message.equals("success")){ Intent intent = new Intent(PhoneZhuCe.this, PhoneZhuCe2.class); startActivity(intent); }else{ Toast.makeText(PhoneZhuCe.this, fromJson.getData().getDescription(), 0) .show(); } } });

    下载数据:

    String path = Environment.getExternalStorageDirectory().getPath();
        String target=path+"/image/"+num+".png";//下载文件保存的路径
        
        HttpUtils http=new HttpUtils();
    //url路径 HttpHandler handler
    =http.download(url, target, true, true,new RequestCallBack<File>() { @Override public void onSuccess(ResponseInfo<File> arg0) { // TODO Auto-generated method stub } @Override public void onFailure(HttpException arg0, String arg1) { // TODO Auto-generated method stub } });
  • 相关阅读:
    大数据量下的SQL Server数据库自身优化
    NodeJS 学习笔记
    SOA、ESB、NServiceBus、云计算 总结
    .NET及.NET Core系统架构
    TCP/IP协议、HTTP协议、SOCKET通讯详解
    web压测工具http_load
    前端面试问题答案汇总--通识篇
    前端面试问题答案汇总--高级篇
    前端面试问题答案汇总--进阶篇
    前端面试问题答案汇总--基础版
  • 原文地址:https://www.cnblogs.com/1426837364qqcom/p/5297317.html
Copyright © 2011-2022 走看看