HTTP Request in Kotlin

后端 未结 11 2493
不知归路
不知归路 2020-11-28 06:59

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 alread

11条回答
  •  鱼传尺愫
    2020-11-28 07:30

    import java.io.IOException
    import java.net.URL
    
    fun main(vararg args: String) {
        val response = try {
            URL("http://seznam.cz")
                    .openStream()
                    .bufferedReader()
                    .use { it.readText() }
        } catch (e: IOException) {
            "Error with ${e.message}."
        }
        println(response)
    }
    

提交回复
热议问题