Exemplo n.º 1
0
 public ApiRequest(
     Context ctx, String url, Class clazz, RequestParams params, OnResultListener resultListener) {
   super();
   mClazz = clazz;
   mOnResultListener = resultListener;
   mContext = ctx;
   // 默认POST
   mMethod = HttpRequest.HttpMethod.POST;
   mUrl = url;
   mOnCallBack = new OnCallBack();
   if (params == null) {
     mRequestParams = new RequestParams();
   } else {
     mRequestParams = params;
   }
   UserInfo user = ((Dian1Application) mContext.getApplicationContext()).getUser();
   if (user != null) {
     mToken = user.getToken();
     if (!TextUtils.isEmpty(mToken)) {
       mRequestParams.addQueryStringParameter("token", mToken);
     }
     LogUtil.i(TAG, user.getToken());
   }
   setupHeaders();
 }
Exemplo n.º 2
0
 @Override
 public void onSuccess(ResponseInfo<String> responseInfo) {
   LogUtil.e(TAG, mUrl + " 返回:" + responseInfo.result);
   DMSResponse response = null;
   try {
     // TODO:第一次连接360免费wifi会返回html
     response = JSONObject.parseObject(responseInfo.result, DMSResponse.class);
     onResult(response);
   } catch (Exception e) {
     LogUtil.e(TAG, mUrl + " " + e.getMessage());
     onResult(
         new DMSResponse(
             String.valueOf(Api.RESULT_CODE_JSONFAIL), mContext.getString(R.string.net_error)));
     return;
   }
 }
Exemplo n.º 3
0
 @Override
 public void onFailure(HttpException error, String msg) {
   LogUtil.e(TAG, mUrl + " " + "msg: " + msg + "error:" + error.getMessage());
   onResult(
       new DMSResponse(
           String.valueOf(Api.RESULT_CODE_NETFAIL),
           mContext.getString(R.string.net_error_tips)));
 }