相关疑难解决方法(0)

改造2 - 动态URL

使用Retrofit 2,您可以在服务方法的注释中设置完整的URL,如:

public interface APIService {
  @GET("http://api.mysite.com/user/list")
  Call<Users> getUsers();
}
Run Code Online (Sandbox Code Playgroud)

但是,在我的应用程序中,我的webservices的URL在编译时是未知的,应用程序在下载的文件中检索它们,所以我想知道如何使用Retrofit 2和完整的动态URL.

我试图设置一个完整的路径,如:

public interface APIService {
  @GET("{fullUrl}")
  Call<Users> getUsers(@Path("fullUrl") fullUrl);
}

new Retrofit.Builder()
  .baseUrl("http://api.mysite.com/")
  .build()
  .create(APIService.class)
  .getUsers("http://api.mysite.com/user/list"); // this url should be dynamic
  .execute();
Run Code Online (Sandbox Code Playgroud)

但在这里,Retrofit并未发现该路径实际上是一个完整的URL并且正在尝试下载 http://api.mysite.com/http%3A%2F%2Fapi.mysite.com%2Fuser%2Flist

有关如何使用这种动态网址进行Retrofit的任何提示吗?

谢谢

android retrofit

153
推荐指数
8
解决办法
9万
查看次数

标签 统计

android ×1

retrofit ×1