【发布时间】:2015-06-03 14:51:43
【问题描述】:
我遇到了重复斜杠的问题,我想知道 Retrofit 中是否有内置解决方案。
我的服务器提供了我们应该使用的基本 URL,如下所示:.setEndpoint(http://some.url.com/)
服务器还向下传递一个路径 URI,该路径 URI 应附加到该端点(带有各种请求)。所以我的服务器可能会发回/channels/videos。
这通过以下方法传递给Retrofit
@GET("/{uri}")
void GET(@Header("Authorization") String authHeader, @Path(value = "uri", encode = false) String uri,
@Header("Cache-Control") String cacheHeaderValue, Callback<Object> callback);
这是有问题的,因为使用 GET 方法命中的 URL 是 http://some.url.com//channels/videos,这在我的情况下无法正常工作。
我尝试从基本端点手动删除尾部斜杠 - 但我仍然看到一个重复的斜杠,我认为这是由 "/{uri}" 和 /channels/videos 引起的。
我认为我的问题可以通过删除 "/{uri}" 中的前导斜杠来解决,但 Retrofit 不允许这样做。并且删除我从服务器返回的路径 URI 中的前导斜杠并不完全可行。
throw methodError("URL path \"%s\" must start with '/'.", path);
retrofit.RetrofitError: GET: URL path "{uri}" must start with '/'.
这个问题还有其他解决方案吗?
相关链接:
Possible duplicate but they describe it a little differently
Jake Wharton saying it should be de-duped in what I think is the situation I'm describing
【问题讨论】:
-
为什么不删除端点 URL 中的 /?像这样
http://some.url.com -
I tried manually stripping out the trailing slash from my base endpoint...我也认为这会解决它,但它似乎来自注释中的前导斜杠以及我从服务器获取的路径。