您的位置:首页 > 其它

远程数据调用

2015-09-24 16:29 225 查看
RequestApi,通过RemoteClient请求,RemoteClient是基于Volley实现的。

对比之前的数据请求,简化了调用,不再需要写接口。

注意:有两种调用方式

一种是所有参数都是加密的。

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;
}
...
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: