【发布时间】:2018-06-07 12:13:00
【问题描述】:
我想使用 POST 方法将一串用户名和密码发布到 php 页面,但我找不到解决方案。因此,我尝试使用 JSONRequest 方法,但它总是给我 Response.ErrorListener 的结果。请帮忙解决。
StringRequest 的代码:
UserNamePassword = "Name=aaa&Password=bbb"
val queue = Volley.newRequestQueue(this)
val stringRequest = StringRequest(Request.Method.POST, url,
Response.Listener<String> { response ->
// Display the first 500 characters of the response string.
println(response.toString())
}, Response.ErrorListener { println("That didn't work!") })
// Add the request to the RequestQueue.
queue.add(stringRequest)
JSONRequest 的代码:
val jsonobj = JSONObject()
jsonobj.put("Name", "aaa")
jsonobj.put("Password", "bbb")
val que = Volley.newRequestQueue(this)
val req = JsonObjectRequest(Request.Method.POST,url,jsonobj,
Response.Listener {
response ->
//println(response["msg"].toString())
println("oooooooooooooookkkkkkkkkkkkkkkkkk")
}, Response.ErrorListener {
println("Error rrrrrrrrrrrrrrr")
}
)
que.add(req)
【问题讨论】:
-
您在浏览器中得到响应了吗?
-
@Redman 是的,仅适用于 stringRequest 方法。但是对于 JsonRequest 方法,它总是转到 Response.ErrorListener。
标签: php android post kotlin android-volley