示例#1
0
    void onRequestFinished(HTTPRequest req, HTTPResponse resp)
    {
        Debug.Log("status code: " + resp.StatusCode);
        Debug.Log("req head: " + req.DumpHeaders());
        Debug.Log("req url: " + req.Uri);
        switch (req.State)
        {
        case HTTPRequestStates.Finished:
            if (resp.IsSuccess)
            {
                Debug.Log(resp.DataAsText);

                Debug.Log("Success");
                UserLoginResponse loginResponse = JsonConvert.DeserializeObject <UserLoginResponse>(resp.DataAsText);
                if (loginResponse.result.code == 0)
                {
                    Debug.Log("登录成功!");
                    Debug.Log("result: " + loginResponse.result.code + " | " + loginResponse.result.description);
                    Debug.Log("userid: " + loginResponse.user.userId);
                    Debug.Log("accessToken: " + loginResponse.accessToken);
                    User user = User.CreateInstance("User") as User;
                    user.SetUser(loginResponse.user.userId, loginResponse.user.nickname, loginResponse.user.username, loginResponse.accessToken, loginResponse.refreshToken);
                    user.SaveUser();
                }
            }
            else
            {
                Debug.Log(resp.DataAsText);

                Debug.Log("Fail");
            }
            break;
        }
    }