Skip to content

HTTP 请求工具

taskflow_http 提供安全的 HTTP 请求能力


📋 可用工具

工具名功能安全性
taskflow_http_request发起 HTTP 请求✅ Medium

🔧 工具详解

request

发起 HTTP 请求。

参数:

json
{
  "url": "string",         // 请求 URL(必填)
  "method": "GET",         // 请求方法(可选)
  "headers": {},           // 请求头(可选)
  "body": {},              // 请求体(可选)
  "timeout": 30000,        // 超时时间(毫秒,可选)
  "followRedirects": true  // 是否跟随重定向(可选)
}

示例:

Claude: 帮我请求 https://api.example.com/data

调用:

json
{
  "name": "taskflow_http_request",
  "arguments": {
    "url": "https://api.example.com/data",
    "method": "GET"
  }
}

返回:

json
{
  "success": true,
  "status": 200,
  "headers": {"content-type": "application/json"},
  "body": {"data": "..."},
  "duration": 234
}

🔒 安全机制

1. URL 验证

所有 URL 都经过严格验证:

typescript
// 验证 URL 格式
const url = new URL(request.url);

// 禁止私有 IP
if (isPrivateIP(url.hostname)) {
  throw new Error('禁止访问私有 IP');
}

// 禁止危险协议
const allowedProtocols = ['http:', 'https:'];
if (!allowedProtocols.includes(url.protocol)) {
  throw new Error('不支持的协议');
}

2. SSRF 防护

防止服务器端请求伪造:

typescript
// 检查目标地址
const ip = await dns.lookup(url.hostname);
if (isInternalIP(ip)) {
  throw new Error('禁止访问内部地址');
}

3. 响应限制

限制项默认值
响应大小5 MB
重定向次数5
超时时间30 秒

4. 敏感头过滤

以下头会被自动过滤:

javascript
// ❌ 被过滤的头
Authorization
Cookie
Set-Cookie
Proxy-Authorization

💡 使用技巧

技巧一:API 测试

Claude: 帮我测试这个 API 端点

Claude 会发起请求并返回响应。

技巧二:数据获取

Claude: 帮我获取网页内容

Claude 会发起 GET 请求并返回 HTML。

技巧三:表单提交

Claude: 帮我提交这个表单

Claude 会发起 POST 请求并返回结果。


🐛 常见问题

Q: 请求被拒绝

A: URL 可能触发了安全规则。检查:

  1. URL 是否是公共地址
  2. 协议是否是 http/https
  3. 是否包含敏感参数

Q: 超时错误

A: 请求时间过长。尝试:

  1. 检查网络连接
  2. 增加超时时间
  3. 使用异步请求

Q: 响应过大

A: 响应超过 5 MB 限制。尝试:

  1. 使用分页
  2. 请求部分数据
  3. 联系管理员提高限制

🔗 相关链接


HTTP 请求有问题随时问我

Released under the MIT License.