-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBulkTask.java
More file actions
21 lines (20 loc) · 1.07 KB
/
Copy pathBulkTask.java
File metadata and controls
21 lines (20 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
// 查询一个已提交的 number_high_value_batch 任务。提交用 multipart,见 README 的 curl 示例。
public class BulkTask {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("NUMDETECT_API_KEY");
if (apiKey == null) throw new IllegalStateException("Set NUMDETECT_API_KEY");
String taskId = args.length > 0 ? args[0] : System.getenv("TASK_ID");
if (taskId == null) throw new IllegalStateException("Pass a task id");
HttpRequest request = HttpRequest.newBuilder(URI.create("https://numdetect.com/api/v1/bulk-tasks/" + taskId))
.header("X-API-Key", apiKey)
.GET()
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.body());
System.out.println(response.body());
}
}