Commit 54d20ace by gao.chao

网络请求增加DNS解析

parent a663a955
package com.mayi.fastdevelop.okhttp;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Dns;
public class HttpDns implements Dns {
@Override
public List<InetAddress> lookup(String hostname) {
List<InetAddress> inetAddresses = new ArrayList<>();
List<InetAddress> hostNameInetAddresses = null;
try {
hostNameInetAddresses = Dns.SYSTEM.lookup(hostname);
} catch (UnknownHostException e) {
e.printStackTrace();
}
if (hostNameInetAddresses != null && hostNameInetAddresses.size() > 0) {
inetAddresses.addAll(hostNameInetAddresses);
}
return inetAddresses;
}
}
\ No newline at end of file
...@@ -40,7 +40,7 @@ public class NetWorkUtil { ...@@ -40,7 +40,7 @@ public class NetWorkUtil {
private NetWorkUtil() { private NetWorkUtil() {
client = new OkHttpClient.Builder() client = new OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS) .connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS).build(); .readTimeout(60, TimeUnit.SECONDS).dns(new HttpDns()).build();
handler = new Handler(Looper.getMainLooper()); handler = new Handler(Looper.getMainLooper());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment