常见问题和疑问(Common issues and questions)#
以下是关于 Webhook 节点 的一些常见问题及对应的解决建议。
🌐 Here are some common issues and questions for the Webhook node and suggested solutions.
监听多个 HTTP 方法(Listen for multiple HTTP methods)#
默认情况下,Webhook 节点仅接受使用单一方法的调用。例如,它可以接受 GET 或 POST 请求,但不能同时接受两者。如果你想接受使用多种方法的调用:
🌐 By default, the Webhook node accepts calls that use a single method. For example, it can accept GET or POST requests, but not both. If you want to accept calls using multiple methods:
- 打开节点 设置。
- 打开 允许多种 HTTP 方法。
- 返回 参数。默认情况下,该节点现在接受 GET 和 POST 请求。你可以在 HTTP 方法 字段中添加其他方法。
Webhook 节点为每个方法都有一个输出,因此你可以根据方法执行不同的操作。
🌐 The Webhook node has an output for each method, so you can perform different actions depending on the method.
使用 HTTP 请求节点触发 Webhook 节点(Use the HTTP Request node to trigger the Webhook node)#
HTTP Request 节点会向你指定的 URL 发送 HTTP 请求。
🌐 The HTTP Request node makes HTTP requests to the URL you specify.
- 创建新工作流程。
- 将 HTTP 请求节点添加到工作流中。
- 从 请求方法 下拉列表中选择一种方法。例如,如果在 Webhook 节点中选择 GET 作为 HTTP 方法,则在 HTTP 请求节点中也选择 GET 作为请求方法。
- 从 Webhook 节点复制 URL,并将其粘贴到 HTTP 请求节点中的 URL 字段。
- 如果使用 Webhook 节点的测试 URL:请使用该 Webhook 节点执行工作流。
- 执行 HTTP 请求节点。
使用 curl 触发 Webhook 节点(Use curl to trigger the Webhook node)#
你可以使用 curl 发送 HTTP 请求来触发 Webhook 节点。
🌐 You can use curl to make HTTP requests that trigger the Webhook node.
/// 注释
在示例中,将 <https://your-n8n.url/webhook/path> 替换为你的 webhook URL。
示例中使用的是 GET 请求。你可以使用在 HTTP 方法 中设置的任何 HTTP 方法。
///
发送不带任何参数的 HTTP 请求:
🌐 Make an HTTP request without any parameters:
1 | |
发送带有请求体参数的 HTTP 请求:
🌐 Make an HTTP request with a body parameter:
1 | |
发送带有请求头参数的 HTTP 请求:
🌐 Make an HTTP request with header parameter:
1 | |
发送 HTTP 请求以发送文件:
🌐 Make an HTTP request to send a file:
1 | |
/path/to/file with the path of the file you want to send.
发送字符串类型的响应(Send a response of type string)#
默认情况下,响应格式为 JSON 或数组。要发送字符串类型的响应:
🌐 By default, the response format is JSON or an array. To send a response of type string:
- 选择 响应模式 > 在上一个节点完成时。
- 选择 Response Data > First Entry JSON。
- 选择 添加选项 > 属性名称。
- 输入包含响应的属性名称。默认为
data。 - 将 编辑字段节点 连接到 Webhook 节点。
- 在“编辑字段”节点中,选择 添加值 > 字符串。
- 在名称字段中输入属性的名称。名称应与第4步中的属性名称相匹配。
- 在 Value 字段中输入字符串值。
- 将 仅保留集合 切换为开启(绿色)。
当你调用 Webhook 时,它会从“编辑字段”节点发送字符串响应。
🌐 When you call the Webhook, it sends the string response from the Edit Fields node.
测试 URL 与生产 URL 对比(Test URL versus Production URL)#
n8n 为每个 Webhook 节点生成两个 Webhook URL:一个 测试 URL 和一个 生产 URL。
🌐 n8n generates two Webhook URLs for each Webhook node: a Test URL and a Production URL.
在构建或测试工作流时,请使用 测试 URL。一旦准备好在生产环境中使用 Webhook URL,请使用 生产 URL。
🌐 While building or testing a workflow, use the Test URL. Once you're ready to use your Webhook URL in production, use the Production URL.
| URL 类型 | 触发方式 | 监听时长 | 编辑器界面显示数据? |
|---|---|---|---|
| 测试 URL | 选择 监听测试事件 并从源触发测试事件。 | 120 秒 | |
| 生产 URL | 发布工作流 | 直到取消发布工作流 |
有关更多信息,请参阅工作流开发。
🌐 Refer to Workflow development for more information.
白名单中的 IP 地址连接失败(IP addresses in whitelist are failing to connect)#
如果你无法从 IP 白名单中的 IP 地址连接,请检查你是否在反向代理后运行 n8n。
🌐 If you're unable to connect from IP addresses in your IP whitelist, check if you are running n8n behind a reverse proxy.
如果是这样,请将 N8N_PROXY_HOPS 环境变量 设置为 n8n 所运行的反向代理数量。
🌐 If so, set the N8N_PROXY_HOPS environment variable to the number of reverse-proxies n8n is running behind.
每个路径和方法只允许一个 Webhook(Only one webhook per path and method)#
n8n 只允许为每个路径和 HTTP 方法组合注册一个 webhook(例如,对 /my-request 的 GET 请求)。这样可以避免关于哪个 webhook 应接收请求的歧义。
🌐 n8n only permits registering one webhook for each path and HTTP method combination (for example, a GET request for /my-request). This avoids ambiguity over which webhook should receive requests.
如果你收到一条消息,提示你选择的路径和方法已被使用,你可以执行以下操作之一:
🌐 If you receive a message that the path and method you chose are already in use, you can either:
- 取消发布具有冲突 Webhook 的工作流。
- 更改冲突 Webhook 的路径和/或方法。
n8n 云上的超时(Timeouts on n8n Cloud)#
n8n Cloud 使用 Cloudflare 来防御恶意流量。如果您的 webhook 在 100 秒内没有响应,传入的请求将以 524 状态码 失败。
🌐 n8n Cloud uses Cloudflare to protect against malicious traffic. If your webhook doesn't respond within 100 seconds, the incoming request will fail with a 524 status code.
因此,对于可能超出此限制的长时间运行进程,你可能需要通过配置两个单独的 Webhook 来引入轮询逻辑:
🌐 Because of this, for long-running processes that might exceed this limit, you may need to introduce polling logic by configuring two separate webhooks:
- 一个 webhook 即可启动长时间运行的进程并立即发送响应。
- 第二个 Webhook,你可以定期调用它来查询流程状态,并在流程完成后检索结果。