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 可能触发了安全规则。检查:
- URL 是否是公共地址
- 协议是否是 http/https
- 是否包含敏感参数
Q: 超时错误
A: 请求时间过长。尝试:
- 检查网络连接
- 增加超时时间
- 使用异步请求
Q: 响应过大
A: 响应超过 5 MB 限制。尝试:
- 使用分页
- 请求部分数据
- 联系管理员提高限制
🔗 相关链接
HTTP 请求有问题随时问我