HTTP JSON android R 和 kotlin 中的请求
HTTP JSON Request in android R and kotlin
我尝试使用 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 构建的。
我在哪里可以更改我的代码?
您应该在 AndroidManifest.xml 文件的 <application>
标记中添加以下 属性:cleartextTrafficPermitted="true"
我尝试使用 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 构建的。 我在哪里可以更改我的代码?
您应该在 AndroidManifest.xml 文件的 <application>
标记中添加以下 属性:cleartextTrafficPermitted="true"