Retrofit 2 removes characters after hostname from base url

后端 未结 1 1571
旧时难觅i
旧时难觅i 2020-12-04 10:27

I\'m using Retrofit to access a RESTful api. The base url is:

http://api.example.com/service

This is the code for the interface:

相关标签:
1条回答
  • 2020-12-04 11:11

    Retrofit 2 uses the same rules that an <a href=""> would.

    The leading / on your relative URL tells Retrofit that it is an absolute path on the host. Here's an example from a presentation I gave showing this:

    Note the incorrect URL which was resolved at the bottom.

    By removing the leading /, the URL then becomes relative and will combine with the path segments which are part of the base URL. Corrected in the presentation the final URL is now correct:

    In your example you do not have a trailing / on the base URL. You probably want to add one so that relative paths are resolved on top of it rather than as a sibling of it.

    0 讨论(0)
提交回复
热议问题