如何在 RESTful Client 中添加路径变量



我发出一个HTTP GET请求。我的代码是 -

    // Set basic authentication
    HttpAuthenticationFeature feature = basicAuth(basicUser, basicPassword);
    SSLContext sslContext= getSSLContext();
    WebTarget webTarget = newRestClient(feature, sslContext, url);      
    Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON_TYPE);
    invocationBuilder = invocationBuilder.header(key, requestHeaders.get(key));
    final Response response = invocationBuilder.get();

有什么方法可以使用调用构建器在 url/NEW_PARAM 中添加路径变量,例如 NEW_PARAM?

为它提供形式url/{param}url,然后你可以执行以下操作:

webTarget = webTarget.resolveTemplate("param", "my-value");

在您的示例中,您可以像这样链接该方法:

WebTarget webTarget = newRestClient(feature, sslContext, url)
                          .resolveTemplate("templateName", "my-value"); 

最新更新