简体   繁体   中英

okhttp3 how to set Dns

I need set a DNS in my app.

I can't figure out how to add it:

//Http Client
OkHttpClient.Builder client = new OkHttpClient.Builder();
    client.addInterceptor(interceptor);
    client.dns("172.10.0.100");

You can set the DNS via the WIFI settings and then just do this:

client.dns(Dns.SYSTEM);

now it should get the info from there.

This is an example of setting an alternative DNS strategy or per host overrides

Dns dns = ...
builder.dns(dns);

DnsOverride.kt

DnsSelector.kt

See this post dns-android-okhttp and add dependency which I defined below, and it will work :)

compile 'dnsjava:dnsjava:2.1.7'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM