如何在 Retrofit 中添加到 API 根目录的 url / 我可以有两个 Rest Adapters 吗?

How to prepend to the url of the API root in Retrofit / Can I have two Rest Adapters?

这就是我设置 RetroFit 客户端的方式。

    RestAdapter.Builder builder = new RestAdapter.Builder();
    builder.setEndpoint(Server.API_ROOT);
    builder.setExecutors(Executors.newFixedThreadPool(5), new ScheduledThreadPoolExecutor(5));
    RestAdapter restAdapter = builder.build();
    REST_CLIENT = restAdapter.create(API.class);

但是,我使用的一些 API 端点是 http://example.com/ and others are http://test.example.com/ 那么我该怎么办?

实际上,我可以为两个不同的 API 配备 2 个适配器吗?

您将必须实施端点

样本: https://medium.com/@kevintcoughlin/dynamic-endpoints-with-retrofit-a1f4229f4a8d

如果您使用的是 2.0 beta+,EndPoint 将重命名为 BaseUrl

此外,请查看 2.0+ 版本的内容:

New: @Url parameter annotation allows passing a complete URL for an endpoint.