我如何打印答案而不是帖子请求的错误?

时间:2019-07-02 07:43:37

标签: android api post kotlin request

我将json和标头发送到API,并且我想在响应json上取回它:

{
  "email": [
    "is already taken"
  ]
}
  

但是我遇到了com.android.volley.ClientError之类的错误

如何获取json?

val queue = Volley.newRequestQueue(this)

    queue.add(accessTokenRequest)
        }
        val accessTokenRequest: JsonObjectRequest = object : JsonObjectRequest(
            Method.POST, url, JSONObject(json),
            Response.Listener<JSONObject> {response ->
                textView.text = "Response is 0-0' : $response \n et le truc envoyé is $json"
            },  Response.ErrorListener {response ->
                textView.text = " KO :( : $response \n et le truc envoyé is $json" }) {
            @Throws(AuthFailureError::class)
            override fun getHeaders(): Map<String, String> {
                var params: MutableMap<String, String> = super.getHeaders()
                    params = HashMap()
               // Log.d("TAGomago", "22$params 22")

                params["Content-Type"] = "application/json"
                params["Authorization"] = "Bearer c87627e164190330138103cdab884c8d982bed7df8d23c30562c3bbb93239f13"
                Log.d("TAGomago", "22$params 22")

                //textView.text = " KO :( : \n et le truc envoyé is $json"
                return params
            }
        }
        val queue = Volley.newRequestQueue(this)

        queue.add(accessTokenRequest)

0 个答案:

没有答案