Android 用httpUtils绑定setion和cookin

绑定获取

httpUtil.send(HttpRequest.HttpMethod.GET, URL.URL_GET_MESSAGE_CODE + "?mobile="+phoneNum, new RequestCallBack<String>() {
    @Override
    public void onSuccess(ResponseInfo<String> responseInfo) {
        String result = responseInfo.result;
        JSONObject jsonObject = JSON.parseObject(result);
        DefaultHttpClient dh = (DefaultHttpClient) httpUtil.getHttpClient();//这一句绑定
        MyCookieStore.cookieStore = dh.getCookieStore();//获取调用

        if (jsonObject != null) {
            if (jsonObject.getInteger("code") == 1) {
                Toast.makeText(RegisterActivity.this, "验证码发送成功", Toast.LENGTH_SHORT).show();
                verfitionConde(mBtnGetVerify);
            } else {
                toast("请求验证码失败");
            }
        }

    }

    @Override
    public void onFailure(HttpException e, String s) {

    }
});




在需要的地方解绑

 private void doCheckVerifyCode(String verifyCode) {
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000 * 10);// 设置超时时间

        http.configCookieStore(MyCookieStore.cookieStore);//解绑
//        RequestParams params = new RequestParams();
//        params.addBodyParameter("sms_code", verifyCode);

        http.send(HttpRequest.HttpMethod.GET, URL.URL_CHECK_MESSAGE_CODE+"?sms_code="+verifyCode,  new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                String result = responseInfo.result;

                JSONObject jsonObject = JSON.parseObject(result);

                if (jsonObject != null) {
                    if (jsonObject.getInteger("code") == 1) {
                        toast(jsonObject.getString("msg"));
                        doRegister();
                    } else {
                        toast(jsonObject.getString("msg"));
                    }
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });
    }

工具类:

/**
 * 绑定seetion和cokei
 */
 import org.apache.http.client.CookieStore;
public class MyCookieStore {
    public static CookieStore cookieStore=null;
}







你可能感兴趣的:(Android 用httpUtils绑定setion和cookin)