使用Retrofit批量请求

sea*_*kej 5 url networking android http retrofit

我想使用Retrofit执行批量请求.它有什么好方法,如何实现它?基本上我要做的是替换URL的查询部分中的一些字符(仅在URL的路径部分中使用替换块 - 使用@Path注释).

这是我的问题的伪代码.

@GET("/v2/multi?requests=/users/self,/venues/search?client_id={client_id}&client_secret={client_secret}&v={v}&ll={ll}&intent={intent}&limit={limit}")
    ProfileSearchVenuesResponse searchVenuesAndProfiles(@ReplaceBy("client_id") String clientId,
                          @ReplaceBy("client_secret") String clientSecret,
                          @ReplaceBy("v") int version,
                          @ReplaceBy("ll") String location,
                          @ReplaceBy("intent") String intent,
                          @ReplaceBy("limit") int limit);
Run Code Online (Sandbox Code Playgroud)

Jak*_*ton 9

@Query 是你在找什么:

@GET("/v2/multi?requests=/users/self,/venues/search")
ProfileSearchVenuesResponse searchVenuesAndProfiles(
    @Query("client_id") String clientId,
    @Query("client_secret") String clientSecret,
    @Query("v") int version,
    @Query("ll") String location,
    @Query("intent") String intent,
    @Query("limit") int limit);
Run Code Online (Sandbox Code Playgroud)

在Retrofit 1.7.0版(昨天发布)中,尝试@Path在原始问题中使用的异常消息指示您正确的解决方案:

URL查询字符串"client_id = {client_id}&client_secret = {client_secret}&v = {v}&ll = {ll}&intent = {intent}&limit = {limit}"必须没有替换块.对于动态查询参数,请使用@Query.