常见问题和疑问#
¥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:
- 打开节点设置。
¥Open the node Settings. 2. 启用“允许多种 HTTP 方法”。
¥Turn on Allow Multiple HTTP Methods. 3. 返回参数。默认情况下,该节点现在接受 GET 和 POST 调用。你可以在“HTTP 方法”字段中添加其他方法。
¥Return to Parameters. By default, the node now accepts GET and POST calls. You can add other methods in the HTTP Methods field.
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 请求 节点向你指定的 URL 发送 HTTP 请求。
¥The HTTP Request node makes HTTP requests to the URL you specify.
- 创建新工作流程。
¥Create a new workflow. 2. 将 HTTP 请求节点添加到工作流中。
¥Add the HTTP Request node to the workflow. 3. 从“请求方法”下拉列表中选择一个方法。例如,如果你在 Webhook 节点中选择 GET 作为 HTTP 方法,则在 HTTP 请求节点中也选择 GET 作为请求方法。
¥Select a method from the Request Method dropdown list. For example, if you select GET as the HTTP method in your Webhook node, select GET as the request method in the HTTP Request node. 4. 从 Webhook 节点复制 URL,并将其粘贴到 HTTP 请求节点的 URL 字段中。
¥Copy the URL from the Webhook node, and paste it in the URL field in the HTTP Request node. 5. 如果使用 webhook 节点的测试 URL:使用 Webhook 节点执行工作流。
¥If using the test URL for the webhook node: execute the workflow with the Webhook node. 6. 执行 HTTP 请求节点。
¥Execute the HTTP Request node.
使用 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.
Note
在示例中,请将 https://your-n8n.url/webhook/path 替换为你的 Webhook URL。这些示例会发出 GET 请求。你可以使用在“HTTP 方法”中设置的任何 HTTP 方法。
¥In the examples, replace https://your-n8n.url/webhook/path with your webhook URL.\ The examples make GET requests. You can use whichever HTTP method you set in HTTP Method.
发送不带任何参数的 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 替换为你要发送的文件的路径。
¥Replace /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:
- 选择“响应模式”>“当最后一个节点完成时”。
¥Select Response Mode > When Last Node Finishes. 2. 选择“响应数据”>“首条记录 JSON”。
¥Select Response Data > First Entry JSON. 3. 选择“添加选项”>“属性名称”。
¥Select Add Option > Property Name.
4. 输入包含响应的属性名称。默认值为 data。
¥Enter the name of the property that contains the response. This defaults to data.
5. 将 编辑字段节点 节点连接到 Webhook 节点。
¥Connect an Edit Fields node to the Webhook node. 6. 在“编辑字段”节点中,选择“添加值”>“字符串”。
¥In the Edit Fields node, select Add Value > String. 7. 在“名称”字段中输入属性名称。名称应与步骤 4 中的属性名称一致。
¥Enter the name of the property in the Name field. The name should match the property name from step 4. 8. 在“值”字段中输入字符串值。
¥Enter the string value in the Value field. 9. 将“仅保留设置”切换为“开启”(绿色)。
¥Toggle Keep Only Set to on (green).
当你调用 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 类型 | 如何触发 | 监听时长 | 数据是否显示在编辑器 UI 中? |
|---|---|---|---|
| 测试 URL | 选择“监听测试事件”并从源触发测试事件。 | 120 秒 | :white_check_mark: |
| 生产环境 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(例如,GET 请求 /my-request)。这样可以避免关于哪个 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 的工作流。
¥Deactivate the workflow with the conflicting webhook.
- 更改冲突 Webhook 的路径和/或方法。
¥Change the webhook path and/or method for one of the conflicting webhooks.
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 即可启动长时间运行的进程并立即发送响应。
¥One webhook to start the long-running process and send an immediate response.
- 第二个 Webhook,你可以定期调用它来查询流程状态,并在流程完成后检索结果。
¥A second webhook that you can call at intervals to query the status of the process and retrieve the result once it's complete.