【发布时间】:2020-09-13 12:03:38
【问题描述】:
我正在使用 kotlin 开发一个 android 应用程序,在这条路上我想使用一个请求来响应来自 restfull 服务器的... 现在看看我从服务器请求它的代码及其真实,但我不知道如何将标头的参数添加到我的请求中
fun sendCode(){
val URL = "https://RestfulSms.com/api/MessageSend"
val body : JSONObject = JSONObject()
val header : JSONObject = JSONObject()
body.put("Messages",messageText )
body.put("MobileNumbers",PhoneNumber )
body.put("LineNumber","***********")
body.put("SendDateTime","")
body.put("CanContinueInCaseOfError","false")
val request :JsonObjectRequest = JsonObjectRequest(Request.Method.POST,
URL,
body,
Response.Listener<JSONObject> { response ->
Log.e(tag, response.toString())
},
Response.ErrorListener{ error ->
Log.e(tag, error.message )
})
//request.headers.put("Content-Type","application/json")
header.put("x-sms-ir-secure-token",tokenKey)
queue.getCache().clear();
queue.add(request)
}
【问题讨论】:
-
不,伙计......我有一个 JsonObjectRequest 设置标题的解决方案
标签: android rest android-studio kotlin android-volley