【问题标题】:How to use @path in retrofit request如何在改造请求中使用@path
【发布时间】:2018-07-29 15:42:50
【问题描述】:

我在改造请求中使用@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);

【问题讨论】:

  • 在请求中尝试@Query
  • 试试这个但不行
  • logcat 有错误吗?
  • 你能分享你的 api url 和浏览器上的响应吗?
  • 这是 Wordpress api url。

标签: retrofit retrofit2 android-json


【解决方案1】:

试试这个

基本网址 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);

【讨论】:

猜你喜欢
  • 2022-07-25
  • 2018-07-24
  • 2022-10-06
  • 2016-12-25
  • 1970-01-01
  • 2016-11-17
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
相关资源
最近更新 更多