gpt4 book ai didi

android - “{parameter}”查询后,如何使用Retrofit将这些Api URL与这些 “?”映射

转载 作者:行者123 更新时间:2023-12-02 13:37:03 24 4
gpt4 key购买 nike

很抱歉无法用问题标题表达我的意思。

如何使用Retrofit映射此URL的参数?

 /aaapi.cgi?q={query}-!{syear},{eyear}-!{snfrate},{enfrate}-!{simdbrate},{eimdbrate}-!{genreid}-!{vtype}-!{audio}-!{subtitle}-!{imdbvotes}-!{downloadable}&t=ns&cl={clist}&st=adv&ob={sortby}&p={page}&sa={andor}

I tried to use @Path to replace this "{value}" where there is not an actual "Query" parameter like q={query}.


@Headers(
value = ["Accept: application/json", "X-Mashape-Key: xxxxx"])
@GET(
"/aaapi.cgi-!{syear},{eyear}-!{snfrate},{enfrate}-!{simdbrate},{eimdbrate}-!{genreid}-!{vtype}-!{audio}-!{subtitle}-!{imdbvotes}-!{downloadable}-!cl={clist}-!ob={sortby}-!p={page}")
fun search(
@Path("syear") startYear: String = "1970",
@Path("eyear") endYear: String = "2019",
@Path("snfrate") startNetflixRate: String = "0",
@Path("enfrate") endNetflixRate: String = "5",
@Path("simdbrate") startImdbRate: String = "0",
@Path("eimdbrate") endImdbRate: String = "10",
@Path("genreid") genreId: String = "0",
@Path("vtype") videoType: String = "Movie",
@Path("audio") audio: String = "Any",
@Path("subtitle") subtitle: String = "Any",
@Path("imdbvotes") imdbVotes: String = "1000",
@Path("downloadable") downloadable: String = "",
@Path("clist") countryList: String = "29",
@Path("sortby") sortBy: String = "Date",
@Path("page") page: String = "1",
@Query("q") query: String = "get:new7",
@Query("t") type: String = "ns",
@Query("st") st: String = "adv",
@Query("sa") andOr: String = "and"
): Call<SearchResponse>

但是当然,它一定是不正确的,因为它会生成以下错误的网址:
https://unogs-unogs-v1.p.mashape.com/aaapi.cgi-!1970,2019-!0,5-!0,10-!0-!Movie-!Any-!Any-!1000-!-!cl=29-!ob=Date-!p=1?q=get%3Anew7&t=ns&st=adv&sa=and

这是一个有效的网址,可返回正确的json文件:
https://unogs-unogs-v1.p.mashape.com/aaapi.cgi?q=get%3Anew7-!1900,2018-!0,5-!0,10-!0-!Any-!Any-!Any-!gt100-!Yes&t=ns&cl=all&st=adv&ob=Relevance&p=1&sa=an

编辑

它适用于:
@GET(
"/aaapi.cgi"
)
fun search(
@Query("q", encoded = true) query: String = "get:new7",
@Query("t") type: String = "ns",
@Query("st") st: String = "adv",
@Query("ob") orderBy: String = "Date",
@Query("sa") andOr: String = "and"

): Call<SearchResponse>

并按照建议传递整个查询:
service.search(
query = "new:7-!1900,2018-!0,5-!0,10-!0-!Any-!Any-!Any-!gt100-!Yes",
type = "ns",
st = "adv",
orderBy = "Relevance",
andOr = "and"
)

最佳答案

没有示例,尚不清楚预期的输出是多少。根据用户输入,如果可能打算替换这些值,则分配值通常不是一个好主意。与URL相比,定义的字段更多;例如,字段q在这里是整个字符串:
?q={query}-!{syear},{eyear}-!{snfrate},{enfrate}-!{simdbrate},{eimdbrate}-!{genreid}-!{vtype}-!{audio}-!{subtitle}-!{imdbvotes}-!{downloadable}
这些@Query字段就足够了,不需要@Path参数:

@Headers(value = ["Accept: application/json", "X-Mashape-Key: xxxxx"])
@GET("aaapi.cgi")
fun getResults(
@Query(value = "q") queryString: String,
@Query(value = "t") type: String,
@Query(value = "st") st: String,
@Query(value = "sa") andOr: String
): Call<SearchResponse>

关于android - “{parameter}”查询后,如何使用Retrofit将这些Api URL与这些 “?”映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53965084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com