简体   繁体   中英

Android Retrofit pass parameter

I am using retrofit to fetch a single post by post-id, I am getting error while passing the post id. I've tried several methods but non of them has returned the right respond.

I tried already:

@GET("?rest_route=/wp/v2/posts/")
    Call<SinglePost> getSinglePost(@FieldMap Map<String, String> map); 

@GET("?rest_route=/wp/v2/posts/")
    Call<SinglePost> getSinglePost(@QueryMap Map<String, String> map);

@GET("?rest_route=/wp/v2/posts/")
    Call<SinglePost> getSinglePost(@QueryMap<String, String> map);

@GET("?rest_route=/wp/v2/posts/{postid}")
    Call<SinglePost> getSinglePost(@Path("postid")int postid);

@GET("?rest_route=/wp/v2/posts/{postid}")
    Call<SinglePost> getSinglePost(@Path("postid")int postid);

@GET("?rest_route=/wp/v2/posts/{postid}")
    Call<SinglePost> getSinglePost(@Field("postid") int postid);

this is the original link https://www.mywordpress.com/?rest_route=/wp/v2/posts/3561

Declare your API call like this

@GET("/")
Call<SinglePost> getSinglePost(@QueryMap Map<String, String> map);

Make a map of parameter and pass it when initializing your API call

HashMap<String, String> map = new HashMap<>();
map.put("rest_route", "/wp/v2/posts/3561");
Call<SinglePost> call = apiService.getSinglePost(map);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM