远程数据调用
2015-09-24 16:29
225 查看
RequestApi,通过RemoteClient请求,RemoteClient是基于Volley实现的。
对比之前的数据请求,简化了调用,不再需要写接口。
注意:有两种调用方式
一种是所有参数都是加密的。
一种是有不加密的参数的。
RemoteClient当前支持get和post方法,并且处理了没有网络的情况。
对比之前的数据请求,简化了调用,不再需要写接口。
注意:有两种调用方式
一种是所有参数都是加密的。
public void getInfo(int customerId, int guiderId, int pageIndex, HttpCallBack callBack) { JSONObject jsonRequest = new JSONObject(); try { jsonRequest.put("GuiderId", guiderId); jsonRequest.put("CustomerId", customerId); jsonRequest.put("PageIndex", pageIndex); jsonRequest.put("PageSize", StringConstantUtils.PAGE_SIZE); } catch (JSONException e) { e.printStackTrace(); } remoteClient.request(Constants.serverUrl, "Easy.GetInfo", jsonRequest, callBack); }
一种是有不加密的参数的。
public void submitComment(int userId, int type, String wikipediaId, String commentContent, HttpCallBack callBack) { JSONObject jsonRequest = new JSONObject(); String method = "Easy.SubmitComment"; try { jsonRequest.put("UserId", userId); jsonRequest.put("WikipediaId", wikipediaId); jsonRequest.put("CommentType", type); addCurrentCity(jsonRequest); remoteClient.encryptToken(jsonRequest, method); jsonRequest.put("CommentContent", commentContent); } catch (Exception e) { e.printStackTrace(); } remoteClient.requestAfterEncrypt(Constants.serverUrl, "Easy.SubmitComment", jsonRequest, callBack); }
RemoteClient当前支持get和post方法,并且处理了没有网络的情况。
public void post(String baseUrl, String method, Map<String, String> jsonRequest, HttpCallBack callBack) { callBack.start(); if(!NetUtil.isNetworkConnected(context)){ ToastUtil.showNotNetToast(context); callBack.onErrorResponse(new VolleyError()); return; } ... }
相关文章推荐
- php模糊查询实例代码
- 安防工程中网线的选择
- Xcode 的正确打开方式——Debugging
- openstack多region的实现
- PHP产生guid的算法一例
- String\StringBuffer\StringBuilder的区别
- Web APi之Web Host消息处理管道(六)
- Java类加载器
- Java基础知识强化62:Arrays工具类之概述和使用
- python socket编程之select
- 图解Android View的scrollTo(),scrollBy(),getScrollX(), getScrollY()
- 让你的Chrome App支持多语言(i18n)
- VMware 10设备CentOs 6.5
- 支持 IE8 IE11 和 FF, Chrome 浏览器的圆角
- linux 的硬链接与软连接
- win平台使用secureCRT通过ssh免密码登陆linux
- 【集训队作业】MONOPLOY
- 如何实现上拉加载,默认加载10条数据,上拉再加载10条数据。
- 关于 XcodeGhost , 如何进行保护APP安全性
- sql server2005分页rownumber()