问题描述
HTTPDNS解析结果中的IP列表是有序的吗?
问题原因
不是。HTTPDNS服务端返回的域名解析结果列表是无序的。HTTPDNS服务器将终端用户的IP信息直接交付给权威DNS,权威DNS会根据终端用户的IP信息进行精准调度返回就近节点IP列表,但是最终HTTPDNS不会对这个列表进行排序。
解决方案
可以使用IP优选接口来对结果IP进行排序,从而尽量得到最优连通性的IP,接口示例代码如下:
Android:
ArrayList<IPRankingBean> list = new ArrayList<IPRankingBean>();
list.add(new IPRankingBean("www.aliyun.com", 8080));
new InitConfig.Builder().setIPRankingList(list);
说明
2.3.2版本新增的方法。
iOS:
HttpDnsService *httpdns = [HttpDnsService sharedInstance];
NSDictionary *IPRankingDatasource = @{
@"www.abc.com" : @80,
@"www.cba.com" : @443,
@"www.bac.com" : @443
};
[httpdns setIPRankingDatasource:IPRankingDatasource];
Harmony:
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { httpdns } from '@aliyun/httpdns';
const ACCOUNT_ID = '这里需要替换为阿里云HTTPDNS控制台的Account ID'
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
httpdns.configService(ACCOUNT_ID, {
context: this.context,
// ************* IP优选配置 begin *************
hostConfigsForIpRanking: [{
host: 'www.aliyun.com',
port: 80
}]
// ************* IP优选配置 end *************
})
}
// 省略其它代码
}
适用于
HTTPDNS
该文章对您有帮助吗?