# HTTP 请求

Source: https://openflow.run/zh-cn/docs/nodes/http-request/
Language: zh-CN
Product version: 0.1.0-beta.77

无需 OpenAPI 文档或应用目录操作，直接调用 HTTP 接口。

HTTP 请求节点（HTTP Request）用于单次 HTTP(S) 调用，负责生成端口、编码参数和解析响应。

## 配置请求

业务配置决定请求方法、查询参数和请求头模式、认证、请求体格式、响应格式及状态码策略。URL 和请求值都放在 `inputs` 中，固定值也一样。

```json
{
  "op": "node.add", "as": "request", "type": "http-request", "name": "Read service status",
  "config": { "method": "GET", "responseFormat": "json", "statusPolicy": "success" },
  "inputs": { "url": { "kind": "value", "value": "https://api.example.com/status" } }
}
```

运行前替换示例地址。逐项配置查询参数或请求头时，先设置该组的字段名，再绑定 `query.NAME` 或 `header.NAME`。整个对象模式则使用 `query` 或 `headers`。

HTTP 请求发起一次 GET 调用，输出 body、statusCode 和 headers。

**输入**
GET https://api.example.com/status

**预期结果**
调用成功的 JSON 接口时，body 包含解析后的响应，statusCode 包含 HTTP 状态码。

**运行前准备**
将示例 URL 替换为实际接口；如需认证，还要配置相应认证信息。

[下载工作流](https://openflow.run/docs/examples/http-status.openflow.json)

## 认证

认证支持节点列出的 Bearer、Basic、API key 等方式。凭据字段接受变量或上游输出，不接受直接写入的固定凭据。Bearer 使用 `auth.token`，Basic 使用 `auth.username` 和 `auth.password`。

认证方式按整体替换。切换参数模式时，会移除已删除端口的绑定，并按编辑契约保留已配置的字段名。

## 结果

输出始终为 `body`、`statusCode` 和 `headers`。JSON 数组仍作为一个完整的 body 值返回。可根据接口选择自动、JSON 或文本解析。

默认成功策略将非 2xx 状态视为失败。如果需要由下游条件节点检查非成功响应，可设置 `statusPolicy: "all"`。网络错误和解析错误仍然会失败。

## 错误处理

HTTP 请求支持普通重试和 `onError` 处理，没有单独的错误执行连线。重试写入请求可能重复远端操作，配置时需要考虑接口的实际行为。

## 资料来源

*   [docs/authoring/node-authoring.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/authoring/node-authoring.md#http-request)
*   [docs/control/contracts/control-api.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/control/contracts/control-api.md#http-request-tasks)
*   [packages/open-flow/src/workbench/browser/runtime/editor/addNodeOptions.ts](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/packages/open-flow/src/workbench/browser/runtime/editor/addNodeOptions.ts)
