2017-06-12 29 views
0

我需要關於如何在改進請求中使用多個參數'@path'的幫助。我嘗試使用單參數'@Path'這種方式工作。在改進URL中製作更多@path

@GET("topics/{id}?userId=58bf87d343c3ccb5793b2e99") 
Call<ResponseBody> artikel(@Path("id") String id); 

,但我想用兩個參數是這樣

ApiService.class:

@GET("topics/{id}?userId={userId}") 
Call<ResponseBody> artikelFeeds(@Path("id") String id, @Path("userId") String userId); 

會拋出錯誤「路徑不能有替換塊」 ,這是改造的一部分客戶端

Call<ResponseBody> get_artikel; 
    Retrofit retrofit; 
    retrofit = new Retrofit.Builder() 
      .baseUrl(Status.HOST_ARTICLE) 
      .addConverterFactory(GsonConverterFactory.create()) 
      .client(httpClient) 
      .build(); 

    ApiService apiService = retrofit.create(ApiService.class); 
    get_artikel = apiService.artikelFeeds(id,userId); 

回答

1

試試這個,

@GET("topics/{id}") 
Call<ResponseBody> artikelFeeds(@Path("id") String id, @Query("userId") String userId); 
+0

如何註釋呢? 'ApiService apiService = retrofit.create(ApiService.class); get_artikel = apiService.artikelFeeds(id,userId);' –

+0

使用相同。沒有變化 –

+0

我得到錯誤代碼500,爲什麼? –

0

您進行查詢後?星座,所以你需要在proccess代碼@Query

@GET("topics/{id}Call<ResponseBody> artikelFeeds(@Path("id") String id, @Query("userId") String userId); 
+0

怎麼樣在這裏先生?像這樣:'get_artikel = apiService.artikelFeeds(id,userId);',我得到了錯誤代碼500 –

+0

'500'錯誤代碼來自服務器,你不會做錯什麼,除非你發送不良信息並弄亂服務器querry 。 –

+0

其工作感謝你 –