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

}
});

 
  

转载于:https://www.cnblogs.com/nanze/p/5384146.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值