Retrofit2 请求路径未按预期工作

Retrofit2 request paths not working as expected

我有这个 Retrofit2 服务定义:

@GET("/samples/{sampleId}")
Observable<Sample> getSampleById(@Path("sampleId") String sampleId);

基数 URL 是 http://xxx.xxx.xxx.xxx:8080/sampledb/。我不工作。我得到 404

但是,如果我将 URL 这个用作基础:http://xxx.xxx.xxx.xxx:8080/ 并且我这样定义服务:

@GET("/sampledb/samples/{sampleId}")

它工作正常。为什么?我不想在每个请求定义中添加 sampledb 前缀。

尝试从您的 GET 注释中删除“/”:@GET("samples/{sampleId}")

Retrofit 2.0 带有新的 URL 解析概念。基础 URL 和 @Url 不仅简单地组合在一起,而且已经以与 HTML 中的 ahref 相同的方式解决

看图

  • Base URL:总是以/

  • 结尾
  • @Url:不要以 /

  • 开头

了解更多信息refer this blog