【发布时间】:2021-10-02 10:32:39
【问题描述】:
我正在使用 ktor 客户端进行休息呼叫。这是我对服务器的调用
suspend fun fetchCustomerSummary(id: Int) : Deferred<CustomerPDSummaryDTO> {
val deffered: Deferred<CustomerPDSummaryDTO> = GlobalScope.async{jsonClient.post<CustomerPDSummaryDTO>("http://localhost:8080/customerSummary"){
contentType(ContentType.Application.Json)
body = GenericIntEQ(theInt = id)
}}
return deffered
}
这是我如何调用该代码并使用返回的值
GlobalScope.launch {
setCustomer("")
val firstRequest = PredictService.fetchCustomerSummary(it.id)
val result = firstRequest.await()
props.importReq(result)
}
【问题讨论】: