创建节点
- 请求节点:在代码中创建请求节点,包含请求的参数、方法、路径和请求头。
- 示例:
new Hiddify().request('GET', '/', { method: 'GET', path: '/', headers: { protocol: 'HTTP', serverid: 'example.com', user: 'user@example.com', userId: 'user_id' } })
- 示例:
创建请求
- 显式创建:在代码中直接创建请求节点:
const request = new Hiddify().request('GET', '/', { method: 'GET', path: '/', headers: { protocol: 'HTTP', serverid: 'example.com', user: 'user@example.com', userId: 'user_id' } });
处理请求
- 使用 Hiddify 的方法处理请求:
- 如果请求返回 2 OK,表示成功:
if (response.status === 2) { console.log('请求成功'); } - 如果请求返回 44 错误,表示失败:
if (response.status === 44) { console.log('请求失败'); }
- 如果请求返回 2 OK,表示成功:
处理响应
- 响应节点:在代码中创建响应节点,包含响应内容。
- 示例:
new Hiddify().response('2 OK', { content: '请求成功'; message: '感谢请求' })
- 示例:
中间节点
- 中间节点将 Hiddify 返回的响应节点传递给客户端:
const response = new Hiddify().response(2, { content: '成功响应' });
处理错误
- 如果客户端请求失败,Hiddify 可能返回错误信息:
if (response.error) { console.error(response.error); }
启动中间节点
- 中间节点将 Hiddify 返回的响应传递给客户端:
client.accept(response.node);
处理多请求
- 同步处理:多个请求按时间顺序处理。
- 异步处理:多个请求同时处理,使用 Hiddify 自动同步处理。
使用配置文件
- 配置文件允许动态生成 Hiddify 节点的参数,提高灵活性:
Hiddify.FORCE_CONFIG = { protocol: 'HTTP', endpoint: '/api', request: { method: 'GET', path: '/', headers: { protocol: 'HTTP', serverid: 'example.com', user: 'user@example.com', userId: 'user_id' } } };
使用 HTTP client 库
- 使用 Hiddify 的内部 HTTP client 库,或自定义通信逻辑。
处理错误
- 定义处理错误的逻辑:
const handleResponse = response => { if (response.status === 2) { console.log('请求成功'); } else if (response.status === 44) { console.log('请求失败'); } };
多节点管理
- 多个节点独立运行或组合使用,通过配置文件控制运行状态。
通过以上步骤,可以熟练掌握 Hiddify 的节点管理,能够有效地处理 HTTP 请求。







京公网安备11000000000001号
京ICP备11000001号