建造一个 url 并进行改造

Build a url with retrofit

我正在使用改造来访问有关电视频道的数据。 我的 url 是这样的:

http://ott.online.meo.pt/catalog/v7/Channels?UserAgent=AND&$filter=substringof(%27MEO_Mobile%27,AvailableOnChannels)%20and%20IsAdult%20eq%20false&$orderby=ChannelPosition%20asc&$inlinecount=allpages

在 Retrofit.Builder() 中我放入了 "the main url" (http://ott.online.meo.pt) 并在接口 Endpoint 中放置了 url 的其余部分。 我这样做了,但我不知道如何把完整的 url

interface Endpoint {
    @Headers("User-Agent: AND")
    @GET("catalog/v7/Channels" )
    fun getChannels() : Call<SerializeChannels>
}

您的改装客户:

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http://ott.online.meo.pt/")
        .build();

您可以通过多种方式定义端点:

硬编码方式如下:

interface Endpoint {
    @GET("catalog/v7/Channels?UserAgent=AND&filter=substringof('MEO_Mobile',AvailableOnChannels)&IsAdult=false&orderby=ChannelPosition asc&inlinecount=allpages" )
    fun getChannels() : Call<SerializeChannels>
}

您还可以使用如下查询参数:

interface Endpoint {
   @GET("catalog/v7/Channels")
   fun getChannels( @Query("UserAgent") String agent, @Query("filter") String filters,@Query("IsAdult") String isAdult,@Query("orderby") String sort,@Query("inlinecount") String count) : Call<SerializeChannels>
}