【问题标题】:HTTP JSON Request in android R and kotlinandroid R 和 kotlin 中的 HTTP JSON 请求
【发布时间】:2021-02-25 06:48:23
【问题描述】:

我尝试使用 Volley 来获得 JSON 响应,但出现了问题。

这是我的代码。

private fun sendGet() {
        val queue = Volley.newRequestQueue(this)
        val url = "http://localhost/Book/all"

        val stringRequest = JsonObjectRequest(Request.Method.GET, url, null,
                { response ->
                    // Display the first 500 characters of the response string.
                    text!!.text = response.toString()
                },
                { error ->
                    text!!.text = error.toString() })

        queue.add(stringRequest)
    }

但它总是要求

com.android. volley. NoConnectionError: java.io. IOException: Cleartext HTTP traffc to localhost not permitted

服务器是从 IIS 构建的。 我在哪里可以更改我的代码?

【问题讨论】:

标签: android kotlin request android-volley httpresponse


【解决方案1】:

您应该在 AndroidManifest.xml 文件的<application> 标签中添加以下属性:cleartextTrafficPermitted="true"

【讨论】:

    猜你喜欢
    • 2018-07-30
    • 2020-12-06
    • 2018-02-20
    • 2021-11-03
    • 2016-03-10
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    相关资源
    最近更新 更多