我正在使用改造在我的 Android 应用程序中使用 API。其中一个端点有一个正斜杠,后跟一个查询。
http://localhost/api/trips/?userId=351da831b08e427d94c65c08b2d17642
但是,当我尝试向该端点发送 GET 时,我没有得到响应。但是,当我在 postman 上尝试时,我得到了回复
这是我的 Retrofit API 服务中的 get 请求
@GET("api/trips/")
Call<GetTripsResponse> getTripsForUser(@Header("Content-Type") String content_type,
@Header("Authorization") String token,
@Query("userId") String userId);
这就是我尝试在代码中调用它的地方:
Call<GetTripsResponse> call = apiService.getTripsForUser("application/json", "Bearer " + Config.TOKEN, userId);
我尝试在请求中发送一个空路径“Blank”。
Call<GetTripsResponse> getTripsForUser(@Header("Content-Type") String content_type,
@Header("Authorization") String token,
@Path("Blank") String blank,
@Query("userId") String userId);
然后我调整我的获取请求以接受空字符串作为路径,这样:
Call<GetTripsResponse> call = apiService.getTripsForUser("application/json", "Bearer " + Config.TOKEN, ,"",userId);
但仍然是相同的空响应
谢谢
最佳答案
在 api 中,用户 ID 用 userId
注释,在链接中显示 dId
将@Query("userId") String userId
替换为@Query("dId") String userId
关于java - 如何在查询前解析正斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56867809/