2017-06-12 50 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

其工作感谢你 –