使用Android KTOR客户端与搜索查询的呼叫API

发布于 2025-02-12 20:00:10 字数 418 浏览 1 评论 0原文

我想使用android ktor-client来运行具有查询的API:

这是主要API:https://www.filimo.com/api/api/en/en/v1/movie/movie/movie/movie/list/list/list/tagid- /1000300/text/{query}/sug/on

如何将{query}传递给请求和ktor?

有base_url配置: ”在这里说明“

I want to use the android Ktor-client to run an API that has a query:

This is the Main Api: https://www.filimo.com/api/en/v1/movie/movie/list/tagid/1000300/text/{Query}/sug/on

How can I pass the {Query} to request with Ktor?

There is the BASE_URL config:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆流年 2025-02-19 20:00:10

这是解决方案:

    KtorModule.provideKtor.use {
            it.get {
                url(HttpRoutes.SEARCH_MOVIE_ENDPOINT.replace("{Query}", query))
            }
        }.body()

This is the solution:

    KtorModule.provideKtor.use {
            it.get {
                url(HttpRoutes.SEARCH_MOVIE_ENDPOINT.replace("{Query}", query))
            }
        }.body()
挖鼻大婶 2025-02-19 20:00:10

就像@saeed Noshadi所说,您可以用实际查询替换URL的已知部分,但是当您获得多个查询时,它可能会变得凌乱。
因此,我建议用您的base_url构建URL,然后根据需要在每个API调用中添加残留部分
喜欢 -

class ApiServiceImpl(val client: HttpClient) {
    suspend fun doHttpCall(baseUrl: String, queries:List<String>,) {
        client.get {
            url(baseUrl + queries.map { "/$it/" } + "sug/on")
        }
     }
}

like @Saeed Noshadi said, you can replace a known part of your URL with the actual query but it might get messy when you get more than one query to add.
hence I suggest to build the url with your BASE_URL and then add the remains part as needed in each API call
like so -

class ApiServiceImpl(val client: HttpClient) {
    suspend fun doHttpCall(baseUrl: String, queries:List<String>,) {
        client.get {
            url(baseUrl + queries.map { "/$it/" } + "sug/on")
        }
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文