1

I am getting this error

System.err: java.net.UnknownHostException: Unable to resolve host "proxy01": No address associated with hostname

I am using OKHTTP. My company have two internet connections. One which requires authentication. When l make OKHTTP call using the guest network, it works as expected. But when l switch network and connect to the secured network, l get the error above. I know my company have proxy server which am suspecting is preventing outgoing network call without authentication. When l connect to the secure network and authenticate with my username and password, am able to open google.com on my phone, however, when l open my app on the phone l get the above error

1
  • maybe use the fully qualified domain name of proxy01. The hostname needs to be resolvable on the machine that the application runs. Commented Aug 23, 2016 at 9:16

1 Answer 1

1

You need to provide proxy settings and its authenticator while working with OKHTTP, Something like this :

Authenticator proxyAuthenticator = new Authenticator() {
  @Override public Request authenticate(Route route, Response response) throws IOException {
       String credential = Credentials.basic(<username>, <password>);
       return response.request().newBuilder()
           .header("Proxy-Authorization", credential)
           .build();
  }
};

OkHttpClient client = new OkHttpClient.Builder()
    .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(<proxyHost>, <proxyPort>)))
    .proxyAuthenticator(proxyAuthenticator)
    .build();

replace tokens <token> with their respective values.

Sign up to request clarification or add additional context in comments.

1 Comment

How come apps l open using my phone works without requiring username and password for the proxy server. Example, whatsapp? Once l authenticate the network, it works flawlessly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.