如何在改造请求中使用@path

时间:2018-07-29 15:42:51

标签: retrofit retrofit2 android-json

我在改造请求中使用@path。实际上是变量调用其他活动。 所以我尝试了@path请求,但是没有用。请帮我,如何解决这个问题。

String CATE_ID = getIntent().getExtras().getString("cateid");

    private String baseURL = "http://www.example.com";

@GET("wp-json/wp/v2/posts?categories={CATEGORY_ID}")
    Call<List<WPPost>> getCatPostInfo(@Path("CATEGORY_ID") String CATEGORY_ID);

  Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        RetrofitArrayApi service = retrofit.create(RetrofitArrayApi.class);
        Call<List<WPPost>>  call = service.getCatPostInfo(CATEGORY_ID);

1 个答案:

答案 0 :(得分:2)

尝试

基本URL http://www.example.com/

改造界面

 @GET("wp-json/wp/v2/posts")
 Call<List<WPPost>> getCatPostInfo(@Query("categories") Integer categories);

改造电话

 Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseURL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    RetrofitArrayApi service = retrofit.create(RetrofitArrayApi.class);
    Call<List<WPPost>>  call = service.getCatPostInfo(CATEGORY_ID);
相关问题