维护通过Swift中的webservice登录的用户会话

时间:2018-06-15 16:09:26

标签: ios json web-services session alamofire

我使用alamofire登录网络服务如下

let url="http://192.169.201.32:9000/users/authenticate"

@IBAction func DoLogin(_ sender: AnyObject) {
    Alamofire.request(url, method: .post, parameters:["username":"andrews","password":"admin2"], encoding: JSONEncoding.default)
        .responseJSON { response in
            print("abcsign in")
            print(response)
            print("abcsign in3")
            print(response.result)
            //to get status code
            if let status = response.response?.statusCode {
                switch(status){
                case 201:
                    print("example success")
                default:
                    print("error with response status: \(status)")
                }
            }
            //to get JSON return value
            if let result = response.result.value {
                let JSON = result as! NSDictionary
                print("abcsign in 2")
                print(JSON)

            }

    }


}

登录Web服务的json out put如下

abcsign in3
SUCCESS
error with response status: 200
abcsign in 2
{
    login =     {
        profilePic = "http://wow-healthcare.com/images/patient/19338image.png";
        token = QUYTXEQQ6C8PIYVDEU;
        userID = 27;
        userName = andrews;
        userProfessionId = 146;
        userProfessionType = 0;
        userRole = patient;
    };
    status =     {
        contextID = S7;
        message =         {
            code = S001;
            details = "Operation Successful";
            type = INFO;
        };
        result = SUCCESS;
        tokenExpired = 0;
    };
}

如何使用json表单维护登录Web服务中特定用户的会话? 您可以从此链接下载示例项目 https://drive.google.com/file/d/1l6kz_cArk6Dq8wU2lRuJG38QbvpTIQBG/view?usp=sharing

0 个答案:

没有答案