的Java /改造/ Robospice:在@ GET命令多个参数?多个、命令、参数、Java

2023-09-06 13:29:54 作者:曾经的一句我爱你°

我使用的改造和Robospice使我的Andr​​oid应用程序的API调用。所有@POST方法工作的伟大,所以做@GET没有在URL中任何参数的命令,但我不能得到任何@GET要求与结束参数工作!

I am using Retrofit and Robospice to make api calls in my android application. All @POST methods work great, and so do @GET commands without any parameters in the URL, but I can't get any @GET calls to work with parameters on the end!

例如,如果我的API路径是我/ API /电话/,我想2个参数参数1,并在URL参数2,get调用将如下所示:

For example, if my api path was "my/api/call/" and I wanted 2 parameters "param1" and "param2" in the url, the get call would look like:

http://www.mysite.com/my/api/call?param1=value1&param2=value2

所以我有我的设置像这样@GET接口:

so I have setup my @GET interface like so:

@GET("/my/api/call?param1={p1}&param2={p2}")
Response getMyThing(@Path("p1")
String param1, @Path("p2")
String param2);

但我得到一个错误说请求网络执行过程中出现的异常:URL查询字符串/我/ API /调用参数1 = {P1}&放大器;参数2 = {P2}的方法getMyThing可能没有替代块? 。

but i get an error saying "An exception occurred during request network execution :URL query string "/my/api/call?param1={p1}&param2={p2}" on method getMyThing may not have replace block."

我是什么做错了吗?

推荐答案

您应该使用的语法如下:

You should be using this syntax:

@GET("/my/API/call")
Response getMyThing(
    @Query("param1") String param1,
    @Query("param2") String param2);

指定URL中的查询参数只有当你知道这两个键和值对,他们是固定的。

Specifying query parameters in the URL is only for when you know both the key and value and they are fixed.