【问题标题】:Get request in KOTLIN在 KOTLIN 中获取请求
【发布时间】:2021-06-18 21:01:03
【问题描述】:

我如何使用这个发送 requestBody :

try {
        data =(URL("<URL>" + path).openConnection() as HttpsURLConnection).apply {
            sslSocketFactory = createSocketFactory(listOf("TLSv1.2"))
            hostnameVerifier = HostnameVerifier { _, _ -> true }
            readTimeout = 5_000
            
        }.inputStream.bufferedReader().readText()
    } catch (e: Exception) {
        println("error").toString()
    }

代码是用 Kotlin 编写的

【问题讨论】:

    标签: kotlin url


    【解决方案1】:

    类似问题here。我强烈推荐一个简单的库,比如http4k

    val client = JavaHttpClient()
    val request = Request(Method.GET, "https://google.com")
    val response = client(request)
    

    【讨论】:

    • 在GET请求中发送请求体有意义吗?
    猜你喜欢
    • 2020-09-27
    • 2014-02-05
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 2020-10-26
    • 2017-09-03
    相关资源
    最近更新 更多