Android 改装2.0中的URL编码错误 @GET(“图像”) 调用getimages(@Query(“where=item\u id”)int item\u id);

Android 改装2.0中的URL编码错误 @GET(“图像”) 调用getimages(@Query(“where=item\u id”)int item\u id);,android,retrofit,retrofit2,urlencode,cfurl-encoding,Android,Retrofit,Retrofit2,Urlencode,Cfurl Encoding,当我使用此选项时,where后面的等号将被编码为%3D,我的服务器不接受该值。我希望在api调用中的where后面有=符号 我的链接是 图像?其中=item_id=1请尝试以下方法: @GET("images") Call<Example> getimages(@Query("where=item_id") int item_id); @GET("images") Call<Example> getimages(@Query("where") String item

当我使用此选项时,where后面的等号将被编码为%3D,我的服务器不接受该值。我希望在api调用中的where后面有=符号

我的链接是 图像?其中=item_id=1

请尝试以下方法:

 @GET("images")
 Call<Example> getimages(@Query("where=item_id") int item_id);
@GET("images")
Call<Example> getimages(@Query("where") String item_id);
@GET(“图像”)
调用getimages(@Query(“where”)字符串item_id);
调用此方法时,必须通过以下方式:

 @GET("images")
 Call<Example> getimages(@Query("where=item_id") int item_id);
@GET("images")
Call<Example> getimages(@Query("where") String item_id);
Service服务=改装.create(Service.class);
Call Call=service.getimages(“item_id=1”);
如果可以成功调用Api,则可以使用字符串连接动态传递值

原因:当传递查询参数时,您只需在
@query(“”
中写入查询参数,当您调用此方法并将值传递给
getimages
方法的“item_id”参数时,将在运行时为其赋值

要了解有关改装的更多信息,请参阅此链接:

添加编码标志

Service service = retrofit.create(Service.class);
Call<Example> call = service.getimages("item_id=1");
@GET(“图像”)
调用getimages(@Query(“where=item\u id”,encoded=true)字符串item\u id);

并在将项目传递给此方法之前对其id进行编码。

对不起,我在两者之间有一个where子句。@Hitesh您能发布您真正想要调用的url吗?你必须使用正斜杠
/{path}
。我使用不带
/
的改装,但它仍然可以。试过了吗this@GET(“images?where=item_id=/{item_id}”)调用getimages(@Path(“item_id”)int item_id);并得到错误URL查询字符串“where=item\u id=/{item\u id}”不能有替换块。对于动态查询参数,使用@query@ChintanSoni这个主意不错。让我来实现它。你的链接是什么?link
是图像吗?where=item\u id
?没有类似的图像吗?where=item\u id=1这很奇怪。您可以尝试使用Path param
@GET(“images?where=item_id={id}”)调用getimages(@Path(“id”)int-id)
已经尝试过。它抛出一个错误,提示使用查询动态url。因为项目id是动态的。您可以用
替换
where=item\u id
,替换为
where%3Ditem\u id