簡體   English   中英

Retrofit 使用參數獲取請求

[英]Retrofit to get request using parameter

我想通過 url 使用參數來通過 retrofit。

Base Url = .../.../...?t=id

“t”這里是我的參數。

Output json數據如下:

{
  "id":"1",
  "names":[
     "xxxxxx",
     "yyyyyy"
  ]

}

我該怎么做? 你能幫我嗎?

你應該聲明接口

public interface RestInterface {

    @GET("/fixed_url/{path_param1}_{path_param2}?")
    Result doGetRequest(@Path("path_param1") String from,
                                        @Path("path_param2") String to,
                                        @Query("get_param1") String getParam1,
                                        @Query("get_param2") String getParam2);
}

構建 retrofit object 實例

Retrofit rtft = Retrofit.Builder()
                .baseUrl("http://your_server_url:port")
                .build();

之后,您可以獲得接口實例並進行 HTTP REST 調用

rtft.create(RestInterface.class).doGetSuggestions(....);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM