【驯鹿司机端APP下载】物流系统新版POST请求通过WCFREST服务:Json格式的http请求

IOS下载

android下载(安智)

参考链接 

http://blog.csdn.net/lamp_zy/article/details/52300629

    //第一版系统登录接口:将手机号和密码通过POST方式发送给服务器,参数放入body中
    private void login(final String phone, final String pwd){

        if(GlobalConstants.DEBUG) { //开启调试
            PrefUtils.setString(LoginActivity.this, "USER_NAME", "13135678021");
            PrefUtils.setString(LoginActivity.this, "PASSWORD", "1234");
            logLogin.log2File(tag, "开启调试");
            Intent intent = new Intent(LoginActivity.this, MainActivity.class);
            LoginActivity.this.startActivity(intent);
            finish();
        }else {

            HttpUtils utils = new HttpUtils(GlobalConstants.HTTP_TIMEOUT);
            RequestParams params = new RequestParams();
            params.addBodyParameter("phone", phone);
            params.addBodyParameter("password", pwd);

            utils.send(HttpRequest.HttpMethod.POST, GlobalConstants.SERVER + "login", params, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    Gson gson = new Gson();
                    mResponse = gson.fromJson(responseInfo.result, Response.class);

                    //System.out.println("服务器返回值"+ result);
                    if (TextUtils.equals(mResponse.result, GlobalConstants.SUCCESS)) {
                        //登录成功就在sharedPreference记住用户名、密码、
                        PrefUtils.setString(LoginActivity.this, "USER_NAME", phone);
                        PrefUtils.setString(LoginActivity.this, "PASSWORD", pwd);
                        logLogin.log2File(tag, "login ok");
                        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                        LoginActivity.this.startActivity(intent);
                        finish();
                    } else {
                        logLogin.log2File(tag, "login failed");
                        Toast.makeText(LoginActivity.this, "用户名或密码错误,请重新登录", Toast.LENGTH_LONG).show();

                    }
                }

                @Override
                public void onFailure(HttpException e, String s) {
                    logLogin.log2File(tag, "login with[]" + e);
                    Toast.makeText(LoginActivity.this, "请检查网络", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

 

    //第二版系统登录接口WEB Service方式:参数放入JSON中
    private void loginJson(final String phone, final String pwd) throws UnsupportedEncodingException {

        HttpUtils utils = new HttpUtils(GlobalConstants.HTTP_TIMEOUT);
        RequestParams params = new RequestParams();
        params.addHeader("Content-Type","application/json");

        JSONObject json = new JSONObject();
        try{
            json.put("phone", phone);
            json.put("password", pwd);
        }catch (JSONException e){
            e.printStackTrace();
        }
        params.setBodyEntity(new StringEntity(json.toString(),"utf-8"));

        utils.send(HttpRequest.HttpMethod.POST, GlobalConstants.SERVER + "login", params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                Gson gson = new Gson();
                mResponse = gson.fromJson(responseInfo.result, Response.class);

                //System.out.println("服务器返回值"+ result);
                if (TextUtils.equals(mResponse.result, GlobalConstants.SUCCESS)) {
                    //登录成功就在sharedPreference记住用户名、密码、
                    PrefUtils.setString(LoginActivity.this, "USER_NAME", phone);
                    PrefUtils.setString(LoginActivity.this, "PASSWORD", pwd);
                    logLogin.log2File(tag, "login ok");
                    Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                    LoginActivity.this.startActivity(intent);
                    finish();
                } else {
                    logLogin.log2File(tag, "login failed");
                    Toast.makeText(LoginActivity.this, "用户名或密码错误,请重新登录", Toast.LENGTH_LONG).show();

                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                logLogin.log2File(tag, "login with[]" + e);
                Toast.makeText(LoginActivity.this, "请检查网络", Toast.LENGTH_SHORT).show();
            }
        });
    }

 

                    if (1 == GlobalConstants.VERSION_NUM) {
                        login(userNameValue,passwordValue);
                    }else {
                        try {
                            loginJson(userNameValue, passwordValue);
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    }

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值