Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit 2 unable to resolve host [closed]

In my previous version of my app I used Apache Client and everything worked and still works. But we decided to move to Retrofit because of some performance gain. The problem is that I get "Unable to resolve host "xxxxxx": No address associated with hostname" every time.

I put this inside manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

May there be anything else I forgot?

This is url: https://www.hbapimanager.azure-api.net/Wallet/CheckNumber

P.S. I have been struggling with this for almost a week

Edited: This is my retrofitFactory class:

private static HttpLoggingInterceptor logging = new HttpLoggingInterceptor()
        .setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);

private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
        .addInterceptor(logging);

private static HttpUrl url = new HttpUrl.Builder()
        .scheme("https")
        .host(Constants.Network.HOST)
        .build();

private static Retrofit.Builder builder =
        new Retrofit.Builder()
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create());

public static <T> T createRetrofitService(final Class<T> clazz) {
    Retrofit retrofit = builder.client(httpClient.build()).build();
    return retrofit.create(clazz);
}

And this is interface for requests

    @Headers({
        Constants.Network.HEADER_TYPE,
        Constants.Network.HEADER_KEY
})
@POST(Constants.Network.CHECK_NUMBER)
Call<StatusData> postCheckNumber(@Body CheckNumberPoRD checkNumberPoRD);

@Headers({
        Constants.Network.HEADER_TYPE,
        Constants.Network.HEADER_KEY
})
@GET(Constants.Network.CHECK_NUMBER)
Call<CheckNumberGRD> getCheckNumber(
        @Query("PrimaryKey") String primaryKey,
        @Query("RowKey") String rowKey
);

And i get

09-06 16:58:50.958 7229-7283/kz.halykbank.halykewallet D/OkHttp: --> POST https://www.hbapimanager.azure-api.net/Wallet/CheckNumber http/1.1
09-06 16:58:50.959 7229-7283/kz.halykbank.halykewallet D/OkHttp: Content-   Type: application/json
09-06 16:58:50.959 7229-7283/kz.halykbank.halykewallet D/OkHttp: Content-Length: 27
09-06 16:58:50.959 7229-7283/kz.halykbank.halykewallet D/OkHttp: Ocp-Apim-Subscription-Key: xxxxxxxxxxxxxxxxxxxxxxxxx
09-06 16:58:50.959 7229-7283/kz.halykbank.halykewallet D/OkHttp: {"phone":"x(xxx)xxx-xx-xx"}
09-06 16:58:50.959 7229-7283/kz.halykbank.halykewallet D/OkHttp: --> END POST (27-byte body)
09-06 16:58:51.666 7229-7283/kz.halykbank.halykewallet D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "www.hbapimanager.azure-api.net": No address associated with hostname
like image 243
Rustam Ibragimov Avatar asked Nov 26 '22 20:11

Rustam Ibragimov


1 Answers

My problem was that I was trying to send request to https://www.example.com. However, there wasn't www.example.com in the hosts of the server, but only example.com.

like image 195
Rustam Ibragimov Avatar answered Nov 30 '22 22:11

Rustam Ibragimov