Category : okhttp

In my dagger graph, I need to provide okhttp with proxy. I am using java.net.InetSocketAddress with java.net.Proxy which causes network on main thread exception. @InstallIn(SingletonComponent::class) @Module class SingletonModule { @Provides fun proxyClient(): OkHttpClient { return OkHttpClient.Builder() .proxy( Proxy(Proxy.Type.HTTP, InetSocketAddress("192.9.09.8", 98)) ).callTimeout(2, TimeUnit.MINUTES).build() } } Suspend function doesn’t seems to work with hilt. Is there a ..

Read more

Why am I getting null? Why is the phone number transmitted, but not the usual string? I’ve been working on this problem all day, please help. firstName_str = firstName.getText().toString(); ip_str = ip; lastName_str = lastName.getText().toString(); email_str = email.getText().toString(); getPhoneNumber_str = firebaseAuth.getCurrentUser().getPhoneNumber(); getPhoneNumber_str = getPhoneNumber_str.replace("+", ""); Log.d("ccp_str2", "firstName_str: " + firstName_str); Log.d("ccp_str2", "ip_str: " + ip_str); ..

Read more

I’m receiving a SocketTimeoutException when accessing the string() method on an OkHttp3 ResponseBody. var response: Response? try { response = client.newCall(request).execute() } catch (exception: IOException) { … } val result = response.body()?.string() Obviously, a crash occurs because the SocketTimeoutException occured outside of my try/catch. I was originally under the impression that execute() performed the entire ..

Read more

I cannot recover the data from my WordPress API with the Retrofit library. The error is : HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "app.divion.fr": No address associated with hostname ApiClient : import androidx.appcompat.app.AppCompatActivity; import retrofit2.Call; import kotlin.contracts.Returns; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; public class ApiClient extends AppCompatActivity { //Adresse de l’Api ..

Read more

I have an id, which I should add to each url’s path, which I did via interceptor. val newRequest = chain.request().newBuilder() newRequest.url(chain.request().url.toString() + "/" + id) return chain.proceed(newRequest.build()) Problems occur with the first endpoint with query parameters. So with this code I got MY_BASE_URL?query_param_1=value1&query_param_2=value2/ID but it should be MY_BASE_URL/ID?query_param_1=value1&query_param_2=value2 Any good idea how to solve ..

Read more

I have a ViewModel that is observing a RxJava Observable in my MainRepo class. I am trying to get my WebsocketListener in the MainRepo class to emit events, but I’m unsure how to do so. MainRepo class: private WebSocket ws; public void createWsConnection() { Request request = new Request.Builder() .url(Constants.WEBSOCKET_ENDPOINT) .addHeader(Constants.WEBSOCKET_HEADERS_KEY, Constants.USER_ID) .build(); OkHttpClient client ..

Read more