https://kotlinlang.org logo
#android
Title
# android
o

Oleh Ponomarenko

04/23/2019, 3:14 PM
Hello guys! How can I get data from response header? I use Retrofit for network requests.
Copy code
@POST("api/auth/login")
    fun loginAsync(@Body loginRequest: LoginRequest): Deferred<LoginResponse>
Copy code
data class LoginResponse(
        val status: String
)
In my response I don't see it, but it exists. http://prntscr.com/nfty4z http://prntscr.com/nftylc
r

rook

04/23/2019, 3:16 PM
No need to make a
LoginResponse
object. Retrofit already has a
Response<T>
wrapper for any response that comes back with the status field you’re looking for
Copy code
@POST("api/auth/login")
    fun loginAsync(@Body loginRequest: LoginRequest): Deferred<Response<ResponseBody>>
Then you can just do
Copy code
val response = loginAsync(LoginRequest()).await()
response.headers()
o

Oleh Ponomarenko

04/23/2019, 3:20 PM
yes, now this works fine, thank you! )
1
2 Views