美文网首页
Retrofit 网络请求框架BaseUrl的拼接问题

Retrofit 网络请求框架BaseUrl的拼接问题

作者: Marlon_IT | 来源:发表于2018-10-12 11:16 被阅读83次

Retrofit的Url组合规则

BaseUrl 和URL有关的注解中提供的值 最后结果
http://localhost:4567/path/to/other/ /post http://localhost:4567/post
http://localhost:4567/path/to/other/ post http://localhost:4567/path/to/other/post
http://localhost:4567/path/to/other/ https://github.com/ikidou https://github.com/ikidou

从上面不能难看出以下规则:

  • 如果你在注解中提供的url是完整的url,则url将作为请求的url。
  • 如果你在注解中提供的url是不完整的url,且不以 / 开头,则请求的url为baseUrl+注解中提供的值
  • 如果你在注解中提供的url是不完整的url,且以 / 开头,则请求的url为baseUrl的主机部分+注解中提供的值

本文取自
怪盗kidou的文章 / 你真的会用Retrofit2吗?Retrofit2完全教程

相关文章

网友评论

      本文标题:Retrofit 网络请求框架BaseUrl的拼接问题

      本文链接:https://www.haomeiwen.com/subject/qubwaftx.html