in httpdns_api_demo/src/main/java/alibaba/httpdns_api_demo/NetworkRequestUsingHttpDNS.java [62:81]
public static HttpURLConnection getHttpURLConnection(String urlString)
throws IOException {
URL url = new URL(urlString);
String originHost = url.getHost();
HttpURLConnection conn;
String dstIp = httpdnsService.getIpByHost(url.getHost());
if (dstIp != null) {
Log.d("HttpDNS Demo", "Get IP from HttpDNS, " + url.getHost() + ": " + dstIp);
urlString = urlString.replaceFirst(url.getHost(), dstIp);
url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
// 设置HTTP请求头Host域
conn.setRequestProperty("Host", originHost);
return conn;
} else {
Log.d("HttpDNS Demo", "Degrade to local DNS.");
return (HttpURLConnection) url.openConnection();
}
}