Uri.Authority 和 Uri.Host 之间的区别?

先来看下两个方法的官方注释:

/**
 * Gets the decoded authority part of this URI. For
 * server addresses, the authority is structured as follows:
 * {@code [ userinfo '@' ] host [ ':' port ]}
 *
 * <p>Examples: "google.com", "bob@google.com:80"
 *
 * @return the authority for this URI or null if not present
 */
 /**
 * 从这个 URI 中获取解码后的 authority
 * 对于服务器地址, authority 的结构是酱紫的 : {@code [ userinfo '@' ] host [ ':' port ]}
 * 
 * 例如 : "google.com", "bob@google.com:80"
 * 
 * @return 返回这个 URI 的 authority, 或者返回 null (如果不存在)
 */
@Nullable
public abstract String getAuthority();


/**
 * Gets the encoded host from the authority for this URI. For example,
 * if the authority is "bob@google.com", this method will return
 * "google.com".
 *
 * @return the host for this URI or null if not present
 */
/**
 * 从这个 URI 的 authority 中获取编码后的 host
 * 例如 : 如果 authority 是 "bob@google.com", 那该方法会返回 "google.com".
 * 
 * @return 返回这个 URI 的 host, 或者返回 null (如果不存在)
 */
@Nullable
public abstract String getHost();

通俗理解就是 hostauthority 的子串,authority 可以包含端口,而 host 不含端口。


看个栗子:

http://www.example.com/
authority	=	www.example.com
host		=	www.example.com

http://255.255.255.255:8080/
authority	=	255.255.255.255:8080
host		=	255.255.255.255
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值