This is the response i am trying to fetch from the api
{
"success": {
"id": 35,
"otp": 9830,
"msg": "Otp has sent on this number"
}
}
The response is working absolutely fine when checked in postman . However when i try to fetch the same json by parsing the response in Hashmap format in android kotlin i get the E/Error: retrofit2.adapter.rxjava2.HttpException: HTTP 401 Unauthorized
Now This is My android rxjava kotlin code as below where i am passing all necessery parameters but the response goes to error block. The code is as follows
override fun login(api_token: String, name: String, mobile: String, lat: String, lon: String, address: String) {
var subscribe = api.login(api_token,mobile.toInt(),lat.toDouble(),lon.toDouble(),address).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ list: LoginParentResponseModel? ->
Log.i("login",list!!.toString())
view.showProgress(false)
view.loadLoginSuccess(list!!.success)
}, { error ->
view.loadLoginFailure("loginfailed")
view.showProgress(false)
view.showErrorMessage("problen"+error.toString())
})
subscriptions.add(subscribe)
}
Now this is the Model class for reponse handling
data class LoginParentResponseModel(val success : Map<String,String>,val error : Map<String,String>)
Now this is the api and its parameters which is fine as like i am using in postman
@FormUrlEncoded
@POST("api/register?")
fun login(@Field("api_token") id: String, @Field("mobile") mobile: Int,@Field("lat") lat: Double,@Field("lon") lon: Double,@Field("address") address: String): Observable<LoginParentResponseModel>
Please help me to resolve this issue. Your help would be much appreciated. Thanks in advance