我在使用Retrofit 2库时遇到了一些麻烦。我想用https请求发送标题和参数,我从日志中得到以下网址:
https://api.trakt.tv/movies/popular(page= '1')限制= 10&安培;扩展=完全,图像
我收到404状态代码。上面的网址是对的吗?
字符串ENDPOINT =“https://api.trakt.tv/”;
@GET("movies/popular(page='{page}')?limit=10&extended=full,images")
public Observable<PopularMoviesResponse> getPopularMovies(@Header("trakt-api-version") String trakt_api_version,
@Header("trakt-api-key") String trakt_api_key,
@Path("page") String page);
/********
* Helper class that sets up a new services
*******/
class Creator {
public static MovieService newSurveiesService() {
Gson gson = new GsonBuilder()
.setDateFormat("dd/MM/yyyy hh:mm:ss")
.create();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(MovieService.ENDPOINT)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit.create(MovieService.class);
}
}
答案 0 :(得分:0)
看起来@GET
中的您的网址是错误的,基于您说网址@CaseyB提供的功能。
@Get("movies/popular?page={page}&limit=10&extended=full,images")
或者,您可以使用@Query
注释让Retrofit
为您处理查询字符串:
@Get("movies/popular")
public Observable<PopularMoviesResponse> getPopularMovies(
@Header("trakt-api-version") String trakt_api_version,
@Header("trakt-api-key") String trakt_api_key,
@Query("page") int page,
@Query("limit") int limit,
@Query("extended") String extended);