【问题标题】:Retrofit changing the URL改造更改 URL
【发布时间】:2016-11-12 00:48:09
【问题描述】:

我对改造有疑问。它会更改我尝试访问的 URL。

我的界面是:

@GET("/movies/top_rated")
Call<ApiResponse<Movie>> getTopRatedMovies(@Query("api_key") String apiKey);

我的客户是:

public static final String BASE_URL = "http://api.themoviedb.org/3/";
private static Retrofit retrofit = null;
public static Retrofit getClient(){
    if(retrofit == null){
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}

我的问题是我要从中检索数据的网站是

http://api.themoviedb.org/3/movies/top_rated?api_key=&lt;&lt;your_key&gt;&gt;

但 Retrofit 将其更改为

http://api.themoviedb.org/movies/top_rated?api_key=&lt;&lt;your_key&gt;&gt;

知道如何解决这个问题吗?

【问题讨论】:

    标签: java android retrofit2


    【解决方案1】:

    我认为你需要更换:

    @GET("/movies/top_rated")
    

    与:

    @GET("movies/top_rated")
    

    【讨论】:

    • 谢谢你,它有效!如果允许,我会在 10 分钟内将此作为接受的答案。
    【解决方案2】:

    基本上,Retrofit 对注解上的前导斜杠所做的是protocol + domain + annotation。哪个,就是你所看到的。

    注释中没有前导斜杠,路径直接附加到基本 URL。

    例如,在网页设计中,您会发现在访问 HTML 中的 CSS 和 Javascript 资源时存在类似的问题。

    【讨论】:

    • 我不知道。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    相关资源
    最近更新 更多