HttpClient
public class HttpClient
源码Source
io/agentscope/runtime/sandbox/manager/util/HttpClient.java:34–123HTTP 客户端,封装与远端服务的连接和调用。位于 io.agentscope.runtime.sandbox.manager.util 包。核心成员包括 post、postJson、get、close、HttpClient。
HTTP client utility class for sending HTTP requests
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public HttpClient() | 初始化 `HttpClient` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String post(String url, Map<String, String> headers, String requestBody) throws IOException | 执行后置相关操作。 Send POST request |
public String postJson(String url, Map<String, String> headers, Object requestData) throws IOException | 执行后置 JSON相关操作。 Send JSON POST request |
public String get(String url, Map<String, String> headers) throws IOException | 按条件读取数据。 Send GET request |
public void close() throws IOException | 关闭连接并释放相关资源。 Close HTTP client |
构造器详情Constructor Detail
HttpClient
public HttpClient()
初始化 HttpClient 实例。
Creates a new instance.
源码Source
io/agentscope/runtime/sandbox/manager/util/HttpClient.java:39–42方法详情Method Detail
post
public String post(String url, Map<String, String> headers, String requestBody) throws IOException
执行后置相关操作。
Send POST request
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
url | String | 服务地址(类型 `String`)。request URL |
headers | Map<String, String> | 请求头(类型 `Map`)。request headers |
requestBody | String | 请求正文(类型 `String`)。request body |
String返回字符串结果。response content
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source
io/agentscope/runtime/sandbox/manager/util/HttpClient.java:53–76postJson
public String postJson(String url, Map<String, String> headers, Object requestData) throws IOException
执行后置 JSON相关操作。
Send JSON POST request
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
url | String | 服务地址(类型 `String`)。request URL |
headers | Map<String, String> | 请求头(类型 `Map`)。request headers |
requestData | Object | 请求数据(类型 `Object`)。request data object |
String返回字符串结果。response content
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source
io/agentscope/runtime/sandbox/manager/util/HttpClient.java:87–90get
public String get(String url, Map<String, String> headers) throws IOException
按条件读取数据。
Send GET request
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
url | String | 服务地址(类型 `String`)。request URL |
headers | Map<String, String> | 请求头(类型 `Map`)。request headers |
String返回字符串结果。response content
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source
io/agentscope/runtime/sandbox/manager/util/HttpClient.java:100–113close
public void close() throws IOException
关闭连接并释放相关资源。
Close HTTP client
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source
io/agentscope/runtime/sandbox/manager/util/HttpClient.java:118–122