首页 > 解决方案 > 改造通过标题和字段获取响应消息

问题描述

我想从我的 API 获取响应消息

这是我的 API.kt

@Headers("Accept: application/json")
@FormUrlEncoded
@POST("attendances/clock-in")
fun employeeClockIn(
    @Header("Authorization") token: String?,
    @Field("username ") username: String?,
    @Field("clock_in_ip_address") clkInIpadd : String?,
    @Field("clock_in_latitude") clkInLat : String?,
    @Field("clock_in_longitude") clkInLang: String?
): Call<ClockInRes>

这是在我的片段中使用 api 的 post 方法

var responseclkin = RetroFitClient().apiService.employeeClockIn("Bearer $passtoken",full_data?.username,getIpv4HostAddress(),location?.latitude.toString(),location?.longitude.toString())
                    println("tesklik : Bearer $passtoken ${full_data?.username} ${getIpv4HostAddress()} ${location?.latitude} + ${location?.longitude}")
                    tapin.setOnClickListener{
                        //isitapin.text= getCurrentDate()
                        responseclkin.enqueue(object : Callback<ClockInRes>{
                            override fun onFailure(call: Call<ClockInRes>, t: Throwable) { Toast.makeText(activity,"Jaringan error, silahkan coba lagi", Toast.LENGTH_SHORT).show() }
                            override fun onResponse(call: Call<ClockInRes>, response: Response<ClockInRes>) {
                                isitapin.text=response.body()?.data?.clock_in
                                Toast.makeText(activity,response.body()?.message , Toast.LENGTH_SHORT).show()
                            }

                        })
                    }

我在邮递员中使用 Header 和 Body 来获得响应,这里是截图 pic1 pic2

我在 Toast 上收到空白消息

标签: kotlinretrofitretrofit2

解决方案


推荐阅读