改造除字符之外的路径编码?

Ras*_*iri 1 java android kotlin retrofit retrofit2

我使用改造和我的界面如下

\n\n
 @GET("{link}")\n fun search(@Path(value = "link", encoded = true) link: String?): Call<Any>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我是否需要对除字符“?\”之外的所有链接使用编码。

\n\n

例子:

\n\n

链接-> /api/search?&query=\xd8\xaa\xd8\xb3\xd8\xaa

\n\n

通过改造编码链接 -> api/search%3F&query=%D8%AA%D8%B3%D8%AA

\n\n

我需要这个链接-> api/search?&query=%D8%AA%D8%B3%D8%AA

\n\n

我不需要将字符\'?\'转换为%3F。\ndo 是什么呢?

\n

小智 5

应该使用 @Url 而不是 @Path

@GET
Call<ResponseClass> list(@Url String url);
Run Code Online (Sandbox Code Playgroud)

它可以很好地处理完整的 URL 以及随后与基本 URL 一起使用的路径。

Retrofit retrofit = Retrofit.Builder()  
  .baseUrl("https://website.com/");
  .build();

MyService service = retrofit.create(MyService.class);  
service.exampleCall("https://another-website.com/example");
service.anotherExampleCall("/only/path/part");
Run Code Online (Sandbox Code Playgroud)