Retrofit
是否会从端点的相对 URL 中删除尾部斜杠?我尝试在我的一个端点上添加尾部斜杠,但是当我使用调试器单步执行并查看 Call
对象时,如果我钻取到 delete.relativeUrl 它不会显示尾部斜杠.
最佳答案
您需要在基本 URL 端点末尾手动添加斜杠。
假设您有这两个改造实例:
无斜线
Retrofit retrofitNoSlash = new Retrofit.Builder()
.baseUrl("https://example.com/api/v5")
.build();
@GET("something")
:https://example.com/api/v5something
@GET("/something")
:https://example.com/something
带斜线
Retrofit retrofitWithSlash = new Retrofit.Builder()
.baseUrl("https://example.com/api/v5/")
.build();
@GET("something")
:https://example.com/api/v5/something
@GET("/something")
:https://example.com/something
所以:手动添加尾部斜杠
关于修改相对 URL 的尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38758570/