android - 使用 Retrofit 批量请求

标签 android http url networking retrofit

我想使用 Retrofit 执行批量请求。它有什么好的方法,如何实现它?基本上我要做的是替换 URL 查询部分中的一些字符(替换 block 只允许在 URL 的路径部分中使用 @Path 注释)。

这是我的问题的伪代码。

@GET("/v2/multi?requests=/users/self,/venues/search?client_id={client_id}&client_secret={client_secret}&v={v}&ll={ll}&intent={intent}&limit={limit}")
    ProfileSearchVenuesResponse searchVenuesAndProfiles(@ReplaceBy("client_id") String clientId,
                          @ReplaceBy("client_secret") String clientSecret,
                          @ReplaceBy("v") int version,
                          @ReplaceBy("ll") String location,
                          @ReplaceBy("intent") String intent,
                          @ReplaceBy("limit") int limit);

最佳答案

@Query是你要找的:

@GET("/v2/multi?requests=/users/self,/venues/search")
ProfileSearchVenuesResponse searchVenuesAndProfiles(
    @Query("client_id") String clientId,
    @Query("client_secret") String clientSecret,
    @Query("v") int version,
    @Query("ll") String location,
    @Query("intent") String intent,
    @Query("limit") int limit);

在 Retrofit 的 1.7.0 版(昨天发布)中,尝试在原始问题中使用 @Path 的异常消息指导您正确的解决方案:

URL query string "client_id={client_id}&client_secret={client_secret}&v={v}&ll={ll}&intent={intent}&limit={limit}" must not have replace block. For dynamic query parameters use @Query.

关于android - 使用 Retrofit 批量请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26288830/

相关文章:

javascript - 从 Postman 到 JBoss 的 HTTP 请求

来自 ffmpeg 的 Http Streaming,如何获取序列数据包?

javascript - 将包含外部js的div追加到js中的另一个div无法正确执行

java - 在Java中查找URI对应的协议(protocol)

node.js - 我可以对 Express 路线进行异常(exception)处理吗?

android - textNoSuggestions 被 2.0.1 模拟器忽略

android - 为任何分辨率创建 Android 动态壁纸

javascript - 一个 URL 包含在另一个 URL 中的参数

Java/安卓 : Return a class name through a method

java - 如何将 XML 布局包含到 Android 库中