Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Request.kt
- import com.pawegio.kandroid.d
- import khttp.responses.Response
- import khttp.structures.cookie.CookieJar
- object Request {
- fun post(url: String, data: Map<String, String>? = null, cookies: CookieJar? = null): Response {
- d("Starting")
- val response = khttp.post(url, data = data, cookies = cookies) //this is where it stuck
- d("Finish")
- return response
- }
- }
- // Where it call
- import android.util.Log
- import kotlinx.coroutines.experimental.runBlocking
- import some.package.utils.network.Request
- object Izone {
- private val LOGIN_URL = //some login url goes here
- fun login(username: String, password: String): Boolean {
- val payload = mapOf(
- "form_action" to "submitted",
- "student_uid" to username,
- "password" to password)
- val response = runBlocking { Request.post(LOGIN_URL, data = payload) } //this is where it stuck
- if (response.statusCode == 200) {
- return true
- } else {
- Log.d("TAG", "${response.statusCode}")
- return false
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement