小编Ste*_*eve的帖子

如何在 Java 对象中映射 HttpResponse

我正在通过 HttpClient 进行 GET REST 调用:

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create(endpoint))
    .GET()
    .header("Authorization", authHeader)
    .header("Content-Type", "application/json")
    .build();

HttpResponse<String> response = client.send(
    request, HttpResponse.BodyHandlers.ofString());
Run Code Online (Sandbox Code Playgroud)

如何在 MyObject 对象中映射响应?首先将其截取为字符串是否正确?另外,我需要传递一个字符串作为路径参数,但我不知道在哪里添加它。

感谢您的支持!!

java rest json get httpclient

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

get ×1

httpclient ×1

java ×1

json ×1

rest ×1