Advertisement
Guest User

Untitled

a guest
Jan 29th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.13 KB | None | 0 0
  1. // Request.kt
  2.  
  3. import com.pawegio.kandroid.d
  4. import khttp.responses.Response
  5. import khttp.structures.cookie.CookieJar
  6.  
  7. object Request {
  8.  
  9.     fun post(url: String, data: Map<String, String>? = null, cookies: CookieJar? = null): Response {
  10.         d("Starting")
  11.         val response = khttp.post(url, data = data, cookies = cookies) //this is where it stuck
  12.         d("Finish")
  13.         return response
  14.     }
  15. }
  16.  
  17. // Where it call
  18.  
  19. import android.util.Log
  20. import kotlinx.coroutines.experimental.runBlocking
  21. import some.package.utils.network.Request
  22.  
  23. object Izone {
  24.     private val LOGIN_URL = //some login url goes here
  25.  
  26.     fun login(username: String, password: String): Boolean {
  27.         val payload = mapOf(
  28.                 "form_action" to "submitted",
  29.                 "student_uid" to username,
  30.                 "password" to password)
  31.         val response = runBlocking { Request.post(LOGIN_URL, data = payload) } //this is where it stuck
  32.         if (response.statusCode == 200) {
  33.             return true
  34.         } else {
  35.             Log.d("TAG", "${response.statusCode}")
  36.             return false
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement