Skip to content

How to retrive data by a post request #1

@Caplimbo

Description

@Caplimbo

Hello, I am trying to using this library for my course study in university, and in the process I encountered a problem about retriving data by a post request. The format

fun login(name: String, password: String): Int {
        var id = -1
        Okkt.instance.Builder().setUrl("/user/findbyname")
            .setParams(hashMapOf("name" to name)).get(object: CallbackRule<User> {
                override suspend fun onFailed(error: String) {
                    Log.w("login", "name not found")
                }

                override suspend fun onSuccess(entity: User, flag: String) {
                    Log.w("login", "found password on server ${entity.password}")
                    if (password == entity.password) {
                        id = entity.userID  // these lines are useless for id outside
                    }
                    else {
                        id = 0
                        Log.w("login error", "false password")
                    }
                }
            })
        return id
    } 

Here I found that id cannot be assigned the value in the "onSuccess" block. How should I use the data retrived by the post request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions