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 } });
    复制代码
  • 相关阅读:
    【转帖】电阻电容的封装
    FT2232H的MCU Host Bus Emulation 模式
    google cpp style guide
    CY7C131 BUSY信号线的接法
    有关沟通的常识
    关于for和foreach,兼顾效率与安全
    绩效面谈中处理分歧的小窍门
    SQL 合并列值和拆分列值
    如何保护.net中的dll文件(防止破解、反编译dll)(转)
    .NET框架图解之五:System.Reflection
  • 原文地址:https://www.cnblogs.com/wbp0818/p/5320697.html
Copyright © 2011-2022 走看看