的Java /改造/ Robospice:在@ GET命令多个参数? [英] Java/Retrofit/Robospice: multiple parameters in @GET command?
问题描述
我使用的改造和Robospice使我的Android应用程序的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:
<一个href="http://www.mysite.com/my/api/call?param1=value1¶m2=value2">http://www.mysite.com/my/api/call?param1=value1¶m2=value2
所以我有我的设置像这样@GET接口:
so I have setup my @GET interface like so:
@GET("/my/api/call?param1={p1}¶m2={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}¶m2={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.
这篇关于的Java /改造/ Robospice:在@ GET命令多个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!