1 year ago

#388386

test-img

Archi

How to send JSON body with GET method in volley library?

I am trying to send JSON body with GET request using volley

{"codes":["T4CFNT7HGBE8DXY3HJHV9DKUV","UU4VEYEEA9UPYC96LE7JJF9HC"]}

The api is working fine in Postman, but calling it using volley, gives me 400 error. Your help is much appreciated. Thank you!!

This is my JSONRequest class

 var jsonObject = JSONObject()
 var activationCodes = JSONArray()
 activationCodes.put("T4CFNT7HGBE8DXY3HJHV9DKUV")
 activationCodes.put("UU4VEYEEA9UPYC96LE7JJF9HC")
 val jsonPayload = jsonObject.put("codes", activationCodes)

 val request = object : JsonObjectRequest(Request.Method.GET, url.toString(),jsonPayload,
                Response.Listener { jsonObject ->
                  
                },

                Response.ErrorListener { error ->
                
                }
            ) {
                override fun getHeaders(): Map<String, String> {
                    val headers = HashMap<String, String>()
                    headers["Content-Type"] = "application/json"
                    if (accessToken != null) {
                        headers["Authorization"] = "Bearer $accessToken"
                    }
                    return headers
                }

json

get

android-volley

0 Answers

Your Answer

Accepted video resources