N
N
Nikita2020-02-14 17:16:54
Android
Nikita, 2020-02-14 17:16:54

Why is Retrofit not sending the request?

The API description contains the following code:

@FormUrlEncoded
    @POST("loginByPass/")
    fun loginByPassword(@Field("login") login: String,
                        @Field("password") password: String,
                        @Field("phone") phone: String) : Observable<AuthResponse>


I create the Retrofit object itself as follows:
class API {
    companion object {
        fun getRetrofitAPI() : IAPI {
            val interceptor = HttpLoggingInterceptor()
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)


            val client = OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .addInterceptor(interceptor)
                .addNetworkInterceptor(interceptor)
                .build()

            val retrofit = Retrofit.Builder()
                .baseUrl(SERVER_ADDRESS)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build()

            return retrofit.create(IAPI::class.java)
        }
    }
}


And the request itself:
api.loginByPassword(login, password, "")
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe({
                Log.w("USER_DB", "CODE: " + it.code)
            }, {
                this.sayError(it.localizedMessage)
            }).dispose()


And in response, silence! According to the logs, as if nothing is being sent, I looked at the sent packets - nothing from the emulator either. The call goes to the server's IP address via HTTP.
Can you suggest what could be the reason?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Yudakov, 2020-02-14
@snitron

I don’t know anything about Retrofit, but ... I suspect that it dispose()is clearly superfluous here.

G
Gregary, 2020-03-02
@Gregary

Here is an excellent tutorial in Russian and Kotlin on how to work with GSON and Retrofit androidschool.ru/courses/android-retrofit-and-gson

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question