implementation'cn.finalteam:okhttpfinal:2.0.7'
1、在你App Application中初始化OkHttpFinal(此初始化只是简单赋值不会阻塞线程)
OkHttpFinalConfiguration.Builderbuilder=newOkHttpFinalConfiguration.Builder();OkHttpFinal.getInstance().init(builder.build());
使用如下:
RequestParams params =new RequestParams();//请求参数
params.addFormDataPart("bankid", bankID);//表单数据
params.addFormDataPart("productid", productd);//表单数据
params.addFormDataPart("remarks", remark);//表单数据
params.addFormDataPart("code", codeMag);//表单数据
params.addFormDataPart("f", imgFile);//上传单个文件
params.addHeader("userid", usID);//添加header信息
HttpRequest.post(Contants.EXCHANGE_DECLARATION_SUBMIT, params,new BaseHttpRequestCallback(){
@Override
public void onStart() {
super.onStart();
startProgressDialog();
}
@Override
protected void onSuccess(BaseBean baseBean) {
super.onSuccess(baseBean);
stopProgressDialog();
if(baseBean.isSuccess()){
Toast.makeText(getApplicationContext(),baseBean.getMsg(),Toast.LENGTH_LONG).show();
copyMassge.setText("");
// Toast.makeText(getApplicationContext(),"提交成功",Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(),baseBean.getErrorMsg(),Toast.LENGTH_LONG).show();
// Toast.makeText(getApplicationContext(),"提交失败",Toast.LENGTH_LONG).show();
}
Log.i("ddd",baseBean.getErrorMsg());
}
@Override
public void onFailure(int errorCode, String msg) {
super.onFailure(errorCode, msg);
stopProgressDialog();
}
@Override
public void onFinish() {
super.onFinish();
stopProgressDialog();
}
});