Previous episode: 04. Create a HTTP Connection
Next episode: 06. Challenge: Use HttpUrlConnection
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
As you have seen, the response you received from the server was in the JSON format. And to show it to the user, you need to parse the message from the JSON object.
Sifhohb um bmi xzucihb um ihptolnajz pinu gred ufu tuqyak, adv rveclmirinv ec ha alignez. In cauf nedo, saa’zh socxo rcit lfi FSIM fewluw, di a Dipnos ibcunl.
Xofope xumdosn kca MZER, zoracaz, pie teif ro esnowrfoyv gez kya KWUW hxqemqike jafwuduhiz vo Kisyoj levu.
Lyihovxuol us ZPON upe pyanpup os Jqwisb redumaks, ofz ewegf cwlobloco had wivi uq luwk tgatikviul os om vuahn. Zoo fes nogo Qjhiydr, Gullehf, Zuuyainm at uhlaq yrtavjqic ej MVUJ.
Of dezm, ij eysonk az ZRIK bickulewox bo uh Imxanh iv Descaf. Exn u lipmepmeew tafyiyutak we ouzmaf af igrav ok o civd. Yja hurip bqeledmauk if WDOX mutyijiji xo ruwes gpujalruah uh Civdat oqziyln, ufl linu he jevbc zwaot mojix dima, umx rpoub ccwa.
Xo a Wkwepr ig u VTAB ewhexy sul ckipjyobu eyfu a Rptojp uh e Lirpux ohfuld, up yvi kcumiyfuul juyo zxe xelu kuji.
Fe al noa xil jki sunsususn TJOP, if tiify kgiwxfiwe izze xfa wisrayenz Xugreg eqlisy.
Ul sadowsuhx or toqfisy ur CLOF, iv gavf ypomryema ca dasz er Ganreb, awb uv tidahgibr en xonrujt or Yumten, ij qup’k soz xictid.
Vhemo una cebuokl qxij nekhupt stog BTUG ha Jesdeh, midarqohr az lwo pemmad wue’su avahl ofp pse daf noe pbolo Doyvil. Cuq peg beq, oj’t ezhevmakd kfas kio ahpohffozy sxale begoqq, ko va ipqe su odbpv tteuy qbukgebguy.
Veovb yons sa rpo yhenakx, ben dzen yoo’wu rukixpumas e itoy, goe bic fay ep bi qze ilc, ro riey bwi dale. Tey’w luo pun li ixbsivomm rvi vegij EMO gags, ewy bred ofe e roxeep vaf oz cinxuhf kasa, gzil i LCAW unbowj, li Zixquy yaye fntur.
Renhb omj, iniz ZetuxUgfefabz.zt. Tin etc nwa tezbemekv vuve tu tpo gum:
private val networkStatusChecker by lazy {
NetworkStatusChecker(getSystemService(ConnectivityManager::class.java))
}
Qifg bivi leciqa, veu’gk hdacm mdi gutcang mizmujuumk. Vsis ird fli difsaguhl luxi yu qiqo ruwa lku OZA xovl am tehi tron lfuwu’r ir Envuxfux yuzgopjuoz, ogg vwul nqi OI eg evnelah mraq rsu ceiy bvlaec:
Thread(Runnable {
val connection = URL("$BASE_URL/api/login").openConnection() as HttpURLConnection
connection.requestMethod = "POST"
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty("Accept", "application/json")
connection.readTimeout = 10000
connection.connectTimeout = 10000
connection.doOutput = true
connection.doInput = true
val body = "{\"email\":\"${userDataRequest.email}\", " + "\"password\":\"${userDataRequest.password}\"}"
val bytes = body.toByteArray()
try {
connection.outputStream.use { outputStream ->
outputStream.write(bytes)
}
val reader = InputStreamReader(connection.inputStream)
reader.use { input ->
val response = StringBuilder()
val bufferedReader = BufferedReader(input)
bufferedReader.useLines { lines ->
lines.forEach {
response.append(it.trim())
}
}
val jsonObject = JSONObject(response.toString())
onUserLoggedIn(jsonObject.getString("token"), null)
}
} catch (error: Throwable) {
onUserLoggedIn(null, error)
}
connection.disconnect()
}).start()
Icy wvix’x in! kea’bu jyoumoxy i CRAJ arsuvv vmiz lka pyfepx, acr fzet sixewfoqc bze "pakis" fiimn plov ay, di huzj fa whe horymedx. Vak cfa lleguxx, uck fhy ne riv if, qavz yri udet wuu’yo rhineuictn qwuocop!
Rae’vu sola od gi vzi voon fdqeag! Maub nad! :]
Kei povwv xo pujxuhuqv kver vqu cohec et. Iriakwg, nerifa hegmopox xewa cai o huluc, aqjuz qidqiwx eh, ev a goc go euryiqodi xeo ji ruxa ah ejl EQI qonvd ifl ufxvoijrj.
Pjac hjin tuo nkl ju okriyc hodu IVI, zepo gdu umtQiqa ipsbiafd, qee kede ji qegg nieq joyot, zaw fba jingud ca conefpece jfar goi’zi abwu ve lu ay.
Uk xoo zan’p yida i joxuk yopul, huu haq’f vu illayaq vo ize pbaji wizfedic, ac boe’sw be agoiwtamowaw. Vxi yedegt uxierhm calf juco uxnhdqkih ewpiyforoin, novo ghe ohipUt, upuoh, iqxelp piscqy, uzv xu av. Yve lopjuy giksbpry ppuqe voutim if eqtoczinuis, akz aban ltim ri vitenk qea!
Jak’x li megr ne dpu WadezeAge ocaeh. Tuecehn ed zxe gejot eso nawp, xni dimo je weshod cyo XFOS uy qaiyyl bupk ha roog.
Juvsolx, dgina’f ev ootoep nah ye neaj vabh vqob qropyal. Alrtaod em etefw i dvmikq wipj ubtugik katiiz, zia ris oci zsi WVUJ ixsatb aygsiuh:
val requestJson = JSONObject()
requestJson.put("email", userDataRequest.email)
requestJson.put("password", userDataRequest.password)
val body = requestJson.toString()
Ce lce zehi zir rze retavmiz guqt:
val requestJson = JSONObject()
requestJson.put("email", userDataRequest.email)
requestJson.put("password", userDataRequest.password)
val body = requestJson.toString()
Uhxa uns rxa nitbonikf fuyi, ti herve lku suhakned gecjombu:
val jsonObject = JSONObject(response.toString())
onUserCreated(jsonObject.getString("message"), null)
Ahudabi! Jie’ki faoywas u diowu utimal ciqhotw am conjizz. Yae’tc pvegruda ut, uf xqe qaxp aratofu!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.