2

我有一个带有这样 URL 的 api 方法:http ://api.website.com/app.php?action=SOMETHING&id=SOME_NUMBER

我对每个请求唯一更改的部分是 id 查询字符串,替换 SOME_NUMBER(例如:http ://api.website.com/app.php?action=SOMETHING&id=556 )。

我正在创建这样的服务:

public interface MyService {
    @GET("acao=SOMETHING")
    Call<ComicBookResponse> get(@Query("id") String id);
}

我使用工厂类返回服务的实例:

public static MyService myService() {
        return new Retrofit.Builder()
                .baseUrl("http://api.website.com/app.php?")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(MyService.class);
    }

但是,请求似乎忽略了 @Query 参数。这有什么问题?

4

1 回答 1

1
public static MyService myService() {
    return new Retrofit.Builder()
            .baseUrl("http://api.website.com")
            .addConverterFactory(GsonConverterFactory.create())
            .build()
            .create(MyService.class);
}

public interface MyService {
    @GET("/app.php")
    Call<ComicBookResponse> get( @Query("action") String action, @Query("id") String id );
}

现在它将形成如下网址:

http://api.website.com/app.php?action=SOMETHING&id=556 // if action=SOMETHING and id=556
于 2016-01-12T11:17:08.610 回答