在相关网址上添加斜杠 [英] Retrofit trailing slash on relative urls

查看:169
本文介绍了在相关网址上添加斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Retrofit是否从端点的相对URL中删除尾部斜杠?我曾尝试在我的一个端点上添加斜杠,但是当我逐步调试时并查看Call对象时,如果我钻入delete.relativeUrl,则不会显示斜杠.

Does Retrofit remove the trailing slash from a relative url for an endpoint? I have tried adding the trailing slash on one of my endpoints but when i step through with a debugger and i look at the Call object, if I drill into the delete.relativeUrl it does not show the trailing slash.

推荐答案

您需要在基本URL端点的末尾手动添加斜杠.

You need to manually add the slash at the end of the base URL endpoint.

假设您有以下两种改装实例:

Let's say you have this two instances of retrofit:

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
    • @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
        • @GET("something"): https://example.com/api/v5/something
        • @GET("/something"): https://example.com/something
        • 所以:手动添加尾部斜杠

          so: add the trailing slash manually

          这篇关于在相关网址上添加斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆