我有一个类似于http://www.myexample.com/rss/choose.php?type=level&id=2的网址,我想在我的Android应用中使用Retrofit。问题在于type是一个参数,可以采用不同的值,例如levelgrade等。
我不能每次type更改都采用Retrofit,因为在TestesInterface中得到了“此处不允许注释”。我一直在寻找这个post并应用于我的应用程序,但是它不起作用。

static final String BASE_URL = "http://www.myexample.com/rss/";

public void start() {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
            .addConverterFactory(SimpleXmlConverterFactory.create()).build();

    TestesInterface testesInterface = retrofit.create(TestesInterface.class);

    Call<Channel> call = testesInterface.loadChannel("choose.php?type=level&id=2");
    call.enqueue(this);
}


我的界面:

public interface TestesInterface {
    @GET
    Call<Channel> loadChannel(@Url type);
}


这使得每次我想将类型更改为其他值时,都应更改testesInterface.loadChannel("choose.php?type=level&id=2")。这行不通。你能帮我么?

最佳答案

经过尝试不同的方法后,我得到了解决方案。
我必须在接口上使用标签@Querytypeid,并在start()中调用它时发送值:

@GET
Call<Channel> loadChannel(@Query("type") String type,
                          @Query("id") String value);

关于java - Android:对动态网址使用翻新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47109512/

10-11 22:42
查看更多