okHttp3 newCall的参数不匹配类型请求
okHttp3 newCall's parameter mismatch type request
okHttpClient?.newCall(请求)?.enqueue(对象:回调{
用于“请求”
类型不匹配。
要求:要求!
找到:Request.Builder
显示。
虽然我找了示例代码,好像是正确的表达方式,但我想知道如何解决。
fun sendMessage(destinationUid: String, title: String, message: String) {
FirebaseFirestore.getInstance().collection("pushtokens").document(destinationUid).get()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
var token = task?.result?.get("pushToken").toString()
var pushDTO = PushDTO()
pushDTO.to = token
pushDTO.notification.title = title
pushDTO.notification.body = message
var body = RequestBody.create(JSON, gson?.toJson(pushDTO))
var request = Request.Builder()
Request.Builder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "key=" + serverKey)
.url(url)
.post(body)
.build()
okHttpClient?.newCall(request)?.enqueue(object : Callback{
override fun onFailure(call: Call?, e: IOException?) {
}
override fun onResponse(call: Call?, response: Response?) {
println(response?.body()?.string())
}
})
}
}
}
var request = Request.Builder()
Request.Builder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "key=" + serverKey)
.url(url)
.post(body)
.build()
问题解决了。
Request.Builder()
这部分写了两遍,出现错误
okHttpClient?.newCall(请求)?.enqueue(对象:回调{
用于“请求”
类型不匹配。 要求:要求! 找到:Request.Builder
显示。
虽然我找了示例代码,好像是正确的表达方式,但我想知道如何解决。
fun sendMessage(destinationUid: String, title: String, message: String) {
FirebaseFirestore.getInstance().collection("pushtokens").document(destinationUid).get()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
var token = task?.result?.get("pushToken").toString()
var pushDTO = PushDTO()
pushDTO.to = token
pushDTO.notification.title = title
pushDTO.notification.body = message
var body = RequestBody.create(JSON, gson?.toJson(pushDTO))
var request = Request.Builder()
Request.Builder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "key=" + serverKey)
.url(url)
.post(body)
.build()
okHttpClient?.newCall(request)?.enqueue(object : Callback{
override fun onFailure(call: Call?, e: IOException?) {
}
override fun onResponse(call: Call?, response: Response?) {
println(response?.body()?.string())
}
})
}
}
}
var request = Request.Builder()
Request.Builder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "key=" + serverKey)
.url(url)
.post(body)
.build()
问题解决了。 Request.Builder() 这部分写了两遍,出现错误