簡體   English   中英

字符串中的WebTarget

[英]WebTarget from String

我正在通過Jersey-Client使用REST API。 該API是分頁的。

Client client = ClientBuilder.newClient()
        .register(HttpAuthenticationFeature.basic(USER_NAME, PASSWORD));

WebTarget target = client.target(HOST).path(API_BASE).path("content");
PageResult pageResult = target.request(JSON).get()readEntity(PageResult.class);

響應看起來像這樣:

{
    "results":[...
    ],
    "start": 0,
    "limit": 25,
    "size": 25,
    "_links": {
        "self": "http://localhost:8090/rest/api/content",
        "next": "/rest/api/content?limit=25&start=25",
        "base": "http://localhost:8090",
        "context": ""
    }
}

用響應正確填充了pageResult對象。 現在,我想創建一個新的WebTarget或重用當前的WebTarget 更改的是查詢參數。

創建新的WebTarget的最簡單方法是什么?

target = client.target(pageResult._links.base).path(pageResult._links.next);

這樣,查詢參數將無法正確解釋。 我也不想自己解析網址。 有什么API? 我可以手動添加查詢參數,但我認為應該有一個類似WebTarget.fromString(pageResult._links.base + pageResult._links.next)

換線

target = client.target(pageResult._links.base).path(pageResult._links.next);

target = client.target(pageResult._links.base + pageResult._links.next)

從杜庫

/**
 * Build a new web resource target.
 *
 * @param uri web resource URI. May contain template parameters. Must not be {@code null}.
 * @return web resource target bound to the provided URI.
 * @throws IllegalArgumentException in case the supplied string is not a valid URI template.
 * @throws NullPointerException     in case the supplied argument is {@code null}.
 */
public WebTarget target(String uri);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM