AS AgentScopeAPI 手册 / API Reference

HttpClient

public class HttpClient
源码Source io/agentscope/runtime/sandbox/manager/util/HttpClient.java:34–123

HTTP 客户端,封装与远端服务的连接和调用。位于 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
urlString服务地址(类型 `String`)。request URL
headersMap<String, String>请求头(类型 `Map`)。request headers
requestBodyString请求正文(类型 `String`)。request body
返回Returns String
返回字符串结果。response content
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/runtime/sandbox/manager/util/HttpClient.java:53–76

postJson

public String postJson(String url, Map<String, String> headers, Object requestData) throws IOException

执行后置 JSON相关操作。

Send JSON POST request

参数Parameters
名称Name类型Type说明Description
urlString服务地址(类型 `String`)。request URL
headersMap<String, String>请求头(类型 `Map`)。request headers
requestDataObject请求数据(类型 `Object`)。request data object
返回Returns String
返回字符串结果。response content
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/runtime/sandbox/manager/util/HttpClient.java:87–90

get

public String get(String url, Map<String, String> headers) throws IOException

按条件读取数据。

Send GET request

参数Parameters
名称Name类型Type说明Description
urlString服务地址(类型 `String`)。request URL
headersMap<String, String>请求头(类型 `Map`)。request headers
返回Returns String
返回字符串结果。response content
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/runtime/sandbox/manager/util/HttpClient.java:100–113

close

public void close() throws IOException

关闭连接并释放相关资源。

Close HTTP client

抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/runtime/sandbox/manager/util/HttpClient.java:118–122
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.