我正在尝试向我制作的Web服务器发出发布请求,但是Volley继续发送没有数据的空请求,导致500错误。
val queue = Volley.newRequestQueue(this)
val jsonParams: MutableMap<String?, String?> =
HashMap()
jsonParams["STATUS"] = "on"
val myRequest: JsonObjectRequest = object : JsonObjectRequest(Method.POST, "http://example.com/url_to_post_to/", JSONObject(
jsonParams as Map<String, String>
), Response.Listener { response -> botStatus.text = response.toString() }, Response.ErrorListener { error -> print("There was a error!") }) {
@Throws(AuthFailureError::class)
override fun getHeaders(): Map<String, String> {
val headers =
HashMap<String, String>()
headers["Content-Type"] = "application/json; charset=utf-8"
//headers["User-agent"] = "My useragent"
return headers
}
}
queue.add(myRequest)
任何帮助将不胜感激。
答案 0 :(得分:0)
好的,我知道了问题所在。我的服务器不接受JSON有效负载请求。我现在也已经切换到使用Fuel库。