You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quarkus RestClient禁用URL编码问题求助

解决Quarkus RestClient对接Zendesk API时URL编码导致的404问题

问题核心是你把查询参数filename直接写在了@Path注解里,导致?被当作路径的一部分进行URL编码成%3F,服务器无法识别正确的接口路径。

正确的做法是将查询参数通过@QueryParam注解单独定义,而非嵌入@Path中,修改后的代码如下:

@ApplicationScoped
@RegisterRestClient
public interface MyDummyService {

    @POST
    @Path("/uploads.json")
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    @Produces(MediaType.APPLICATION_JSON)
    @ClientHeaderParam(name = "Content-Type", value = "{calculateContentType}")
    String uploadFile(
            @QueryParam("filename") String filename,
            @NotBody String contentType,
            byte[] file);

    default String calculateContentType(ComputedParamContext context) {
        return context.methodParameters().get(1).value().toString();
    }
}

修改说明:

  • 移除@Encoded注解:该注解会强制对路径中的特殊字符编码,而我们需要让?作为查询参数的分隔符保留,不需要编码
  • @Path仅保留接口路径部分/uploads.json,查询参数filename通过@QueryParam注解声明,RestClient会自动在URL后拼接?filename=xxx,不会对?进行编码
  • 调用代码无需修改,参数顺序与接口定义对应即可

这样调整后,请求URL会正确生成为https://mydummyserver.com/api/v2/uploads.json?filename=order_issue.png,与原curl命令的请求格式一致,就能正常对接Zendesk API了。

内容的提问来源于stack exchange,提问作者anthony44

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 10:32:37