在执行GET请求时以及如何在执行POST请求时如何从URL的标题中获取状态代码及其信息。
到目前为止,我拥有的这种方法具有以下代码:
progress_circular.visibility = View.VISIBLE
//Using Volley Networking Lib
val requestQueue = Volley.newRequestQueue(this@MainActivity)
val stringRequest = object :StringRequest(
Request.Method.POST, downloadURL,
Response.Listener<String> { response ->
try {
val jsonObject = JSONObject(response) //creating JSON Object from server response
val serveResponse = jsonObject.getString("origin") //getting the string
progress_circular.visibility = View.INVISIBLE
Toast.makeText(applicationContext,serveResponse,Toast.LENGTH_LONG).show() //Toast of server response
scheduledTimer() //start 5 second count down to do another network request
} catch (e: JSONException) {
e.printStackTrace()
}
}, Response.ErrorListener {
Toast.makeText(applicationContext, "Error something is wrong", Toast.LENGTH_LONG).show()
requestQueue.stop()
}){
}
requestQueue.add(stringRequest)
我已经研究并看到了与在单独的类中覆盖parseNetworkResponse有关的内容,但是不确定如何实现它以及通过将URL传递给它来获取状态代码和消息的方法