I'm completely new to
Kotlin. I want to do a login validation using POST method and to get some information
using GET method. I've URL, server Username and Password already of my previous project.
I didn't find any proper example project which uses this thing. Anyone please suggest me
any working example where I can use GET and POST method in HTTP
request
Sunday, 3 December 2017
android - HTTP Request in Kotlin
itemprop="text">
Answer
For Android, href="https://developer.android.com/training/volley/index.html"
rel="noreferrer">Volley is a good place to get started. For all platforms,
you might also want to check out rel="noreferrer">ktor
client.
However, you can use standard libraries
you would use in Java. For example, with HttpURLConnection
you
can do:
fun sendGet() {
val url = URL("http://www.google.com/")
with(url.openConnection() as HttpURLConnection) {
requestMethod = "GET" //
optional default is GET
println("\nSent 'GET' request to URL :
$url; Response Code : $responseCode")
inputStream.bufferedReader().use {
it.lines().forEach { line ->
println(line)
}
}
}
}
Or
simpler:
URL("https://google.com").readText()
Subscribe to:
Post Comments (Atom)
php - file_get_contents shows unexpected output while reading a file
I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...
-
I have an app which needs a login and a registration with SQLite. I have the database and a user can login and register. But i would like th...
-
I got an error in my Java program. I think this happens because of the constructor is not intialized properly. My Base class Program public ...
-
I would like to use enhanced REP MOVSB (ERMSB) to get a high bandwidth for a custom memcpy . ERMSB was introduced with the Ivy Bridge micro...
No comments:
Post a Comment