如何在凌图库中使用GET方法发送JSON主体?
我正在尝试使用 volley 通过 GET 请求发送 JSON 正文
{"codes":["T4CFNT7HGBE8DXY3HJHV9DKUV","UU4VEYEEA9UPYC96LE7JJF9HC"]}
API 在 Postman 中工作正常,但使用 volley 调用它会出现 400 错误。 非常感谢您的帮助。谢谢你!!
这是我的 JSONRequest 类
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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论