I try to POST these login and password
{
"userLogin": "Mark",
"userPassword": "Pencil"
}
According to POSTMAN, where I put above JSON as a raw code, I got an empty response body and response code: 200 (Logging is succesful). But I can't achieve it in Android Studio. Here is an API interface
interface LoginService {
@POST("login")
fun userLogin(
@Query("userLogin") userLogin: String,
@Query("userPassword") userPassword: String
):Call<Void>
}
And here is Retrofit:
fun checkLoginData() {
val retrofit = Retrofit.Builder()
.baseUrl("myurl...")
.addConverterFactory(GsonConverterFactory.create())
.build()
val service = retrofit.create(LoginService::class.java)
val call = service.userLogin("Mark", "Pencil")
call.enqueue(object : Callback<Void>{
override fun onResponse(call: Call<Void>, response: Response<Void>) {
if(response.code() == 200){
Toast.makeText(applicationContext,"Logged in", Toast.LENGTH_SHORT).show()
}
}
override fun onFailure(call: Call<Void>, t: Throwable) {
Toast.makeText(applicationContext,"Error", Toast.LENGTH_SHORT).show()
}
})
}
I suppose that my LoginService
is created incorrectly because there is always onFailure response. How should I do it rightly?