okHttp fails with retrofit while using vpn

Viewed 621

I've been using my code on my company networks and it works really fine, but when I want to use it from my home (using a vpn to connect to the company network), it fails saying : Unable to resolve host X: No adress associated with hostname.

What is weird is that I actually can use the link in the browser (it works fine). Is there any configuration that I need to add?

            OkHttpClient defaultHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Interceptor.Chain chain) throws IOException {
                        Request authorisedRequest = chain.request().newBuilder()
                                .addHeader("Authorization", TNConstants.BASIC +
                                        Base64.encodeToString((username+ ":" + password).getBytes(), Base64.NO_WRAP)).build();
                        return chain.proceed(authorisedRequest);
                    }}).build();

It actually fails in the chain.proceed(authorisedRequest) function. Please help me with that. Thank you!

1 Answers

You may want to try okHttpClient.connectionPool.evictAll() before your request call that may resolve your issue

Related