【问题标题】:Append question mark to url retrofit android将问号附加到 url 改造 android
【发布时间】:2016-08-25 09:06:04
【问题描述】:

美好的一天。我想得到这样的网址http//:www.someurl.com/someRedirect/anotherRedirect/?searchCriteria

问题是我不能在改造后附加问号,如果我这样做的话

@GET("someRedirect/anotherRedirect/{searchCriteria}")
    Call<ResponseBody> getProductsList(@Path("searchCriteria") String appendedUrl);

并调用此方法并附加 ?马克,它只会放一些奇怪的 %3fb 什么的,如果我喜欢这个

@GET("someRedirect/anotherRedirect/")
    Call<ResponseBody> getProductsList(@Query("searchCriteria") String appendedUrl);

改造将提供类似http//:www.someurl.com/someRedirect/anotherRedirect/?searchCriteria=searchCriteria的链接...这个库到底有什么问题?如何简单地构建我想要的网址?

【问题讨论】:

  • 你明白了吗?
  • 是的,只接受下面的答案,因为它是正确的

标签: android networking get retrofit


【解决方案1】:

您使用的是 Retrofit 1 还是 2?在任何情况下,Retrofit URL 都会默认对路径进行编码。不过,您可以轻松禁用它:

如果你使用 1,那么你应该使用 @EncodedPath 而不是 @Path

如果你使用 2,那么你应该使用@Path(value = "searchCriteria", encoded = true)

【讨论】:

  • 使用第二个,好吧让我试试
  • 尝试更多选项,但我认为你的想法是解决方案
猜你喜欢
  • 2016-09-03
  • 2011-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 2021-11-28
相关资源
最近更新 更多