Skip to content

HTTP 请求节点#

¥HTTP Request node

HTTP 请求节点是 n8n 中最通用的节点之一。它允许你发出 HTTP 请求,以从任何具有 REST API 的应用或服务查询数据。你可以将“HTTP 请求”节点作为常规节点使用,也可以将其附加到 AI 代理 节点,用作 tool 节点。

¥The HTTP Request node is one of the most versatile nodes in n8n. It allows you to make HTTP requests to query data from any app or service with a REST API. You can use the HTTP Request node a regular node or attached to an AI agent to use as a tool.

使用此节点时,你将创建一个 REST API 调用。你需要对基本的 API 术语和概念有所了解。

¥When using this node, you're creating a REST API call. You need some understanding of basic API terminology and concepts.

你可以通过两种方式创建 HTTP 请求:配置 node 参数导入 curl 命令

¥There are two ways to create an HTTP request: configure the node parameters or import a curl command.

Credentials

请参阅 HTTP 请求凭据 以了解有关设置身份验证的指导。

¥Refer to HTTP Request credentials for guidance on setting up authentication.

节点参数#

¥Node parameters

方法#

¥Method

选择用于请求的方法:

¥Select the method to use for the request:

  • DELETE

  • GET

  • HEAD

  • OPTIONS

  • PATCH

  • POST

  • PUT

URL#

输入你要使用的端点。

¥Enter the endpoint you want to use.

验证#

¥Authentication

n8n 建议在可用时使用“预定义凭据类型”选项。与配置通用凭据相比,它提供了一种更简便的凭据设置和管理方式。

¥n8n recommends using the Predefined Credential Type option when it's available. It offers an easier way to set up and manage credentials, compared to configuring generic credentials.

预定义凭据#

¥Predefined credentials

n8n 支持的集成的凭据,包括内置节点和社区节点。使用预定义凭据类型进行自定义操作,无需额外设置。有关更多信息,请参阅 自定义 API 操作

¥Credentials for integrations supported by n8n, including both built-in and community nodes. Use Predefined Credential Type for custom operations without extra setup. Refer to Custom API operations for more information.

通用凭据#

¥Generic credentials

n8n 不支持的集成的凭据。你需要手动配置身份验证过程,包括指定所需的 API 端点、必要参数和身份验证方法。

¥Credentials for integrations not supported by n8n. You'll need to manually configure the authentication process, including specifying the required API endpoints, necessary parameters, and the authentication method.

你可以选择以下方法之一:

¥You can select one of the following methods:

  • 基本身份验证

¥Basic auth

  • 自定义身份验证

¥Custom auth

  • 摘要式身份验证

¥Digest auth

  • 标头身份验证

¥Header auth

  • OAuth1 API

  • OAuth2 API

  • 查询身份验证

¥Query auth

有关设置每种凭证类型的更多信息,请参阅 HTTP 请求凭据

¥Refer to HTTP request credentials for more information on setting up each credential type.

发送查询参数#

¥Send Query Parameters

查询参数用作 HTTP 请求的过滤器。如果你正在交互的 API 支持此功能,并且你发出的请求需要过滤器,请启用此选项。

¥Query parameters act as filters on HTTP requests. If the API you're interacting with supports them and the request you're making needs a filter, turn this option on.

使用以下可用选项之一指定查询参数:

¥Specify your query parameters using one of the available options:

  • 使用字段如下:输入查询参数的名称/值对。要输入更多查询参数名称/值对,请选择“添加参数”。名称是你要筛选的字段的名称,值是筛选值。

¥Using Fields Below: Enter Name/Value pairs of Query Parameters. To enter more query parameter name/value pairs, select Add Parameter. The name is the name of the field you're filtering on, and the value is the filter value.

  • 使用 JSON:输入 JSON 以定义查询参数。

¥Using JSON: Enter JSON to define your query parameters.

请参阅你服务的 API 文档以获取详细指南。

¥Refer to your service's API documentation for detailed guidance.

发送邮件头#

¥Send Headers

使用此参数随请求发送标头。标头包含有关请求的元数据或上下文。

¥Use this parameter to send headers with your request. Headers contain metadata or context about your request.

使用可用选项之一指定标头:

¥Specify Headers using one of the available options:

  • 使用字段如下:输入请求头参数的名称/值对。要输入更多请求头参数名称/值对,请选择“添加参数”。名称是你要设置的标头,值是你要为该标头传递的值。

¥Using Fields Below: Enter Name/Value pairs of Header Parameters. To enter more header parameter name/value pairs, select Add Parameter. The name is the header you wish to set, and the value is the value you want to pass for that header.

  • 使用 JSON:输入 JSON 以定义请求头参数。

¥Using JSON: Enter JSON to define your header parameters.

请参阅你服务的 API 文档以获取详细指南。

¥Refer to your service's API documentation for detailed guidance.

发送正文#

¥Send Body

如果你需要在 API 请求中发送请求体,请启用此选项。

¥If you need to send a body with your API request, turn this option on.

然后选择与你要发送的正文内容格式最匹配的正文内容类型。

¥Then select the Body Content Type that best matches the format for the body content you wish to send.

表单 URL 编码#

¥Form URLencoded

使用此选项可将正文以 application/x-www-form-urlencoded 格式发送。

¥Use this option to send your body as application/x-www-form-urlencoded.

使用可用选项之一指定正文:

¥Specify Body using one of the available options:

  • 使用字段如下:输入请求体参数的名称/值对。要输入更多请求体参数名称/值对,请选择“添加参数”。名称应与表单字段名称一致,值应为你希望设置该字段的值。

¥Using Fields Below: Enter Name/Value pairs of Body Parameters. To enter more body parameter name/value pairs, select Add Parameter. The name should be the form field name, and the value is what you wish to set that field to.

  • 使用单字段:将你的名称/值对以 fieldname1=value1&fieldname2=value2 格式输入到单个正文参数中。

¥Using Single Field: Enter your name/value pairs in a single Body parameter with format fieldname1=value1&fieldname2=value2.

请参阅你服务的 API 文档以获取详细指南。

¥Refer to your service's API documentation for detailed guidance.

表单数据#

¥Form-Data

使用此选项可将正文以 multipart/form-data 格式发送。

¥Use this option to send your body as multipart/form-data.

通过选择参数类型来配置正文参数:

¥Configure your Body Parameters by selecting the Parameter Type:

  • 选择“表单数据”以输入名称/值对。

¥Choose Form Data to enter Name/Value pairs.

  • 选择“n8n 二进制文件”以从节点有权访问的文件中提取正文。

¥Choose n8n Binary File to pull the body from a file the node has access to.

  • 名称:输入要设置的字段的 ID。

    ¥Name: Enter the ID of the field to set.

  • 输入数据字段名称:输入包含要处理的二进制文件数据的输入字段名称。

    ¥Input Data Field Name: Enter the name of the incoming field containing the binary file data you want to process.

选择“添加参数”以输入更多参数。

¥Select Add Parameter to enter more parameters.

请参阅你服务的 API 文档以获取详细指南。

¥Refer to your service's API documentation for detailed guidance.

JSON#

使用此选项可将正文以 JSON 格式发送。

¥Use this option to send your body as JSON.

使用可用选项之一指定正文:

¥Specify Body using one of the available options:

  • 使用字段如下:输入请求体参数的名称/值对。要输入更多请求体参数名称/值对,请选择“添加参数”。

¥Using Fields Below: Enter Name/Value pairs of Body Parameters. To enter more body parameter name/value pairs, select Add Parameter.

  • 使用 JSON:输入 JSON 以定义请求体。

¥Using JSON: Enter JSON to define your body.

请参阅你服务的 API 文档以获取详细指南。

¥Refer to your service's API documentation for detailed guidance.

n8n 二进制文件#

¥n8n Binary File

使用此选项可将存储在 n8n 中的文件内容作为正文发送。

¥Use this option to send the contents of a file stored in n8n as the body.

输入包含文件的输入字段名称作为“输入数据字段名称”。

¥Enter the name of the incoming field that contains the file as the Input Data Field Name.

有关如何格式化文件的详细指南,请参阅你服务的 API 文档。

¥Refer to your service's API documentation for detailed guidance on how to format the file.

Raw#

使用此选项可在请求体中发送原始数据。

¥Use this option to send raw data in the body.

  • 内容类型:输入用于原始请求体内容的 Content-Type 标头。请参阅 IANA 媒体类型 文档,查看完整的 MIME 内容类型列表。

¥Content Type: Enter the Content-Type header to use for the raw body content. Refer to the IANA Media types documentation for a full list of MIME content types.

  • 正文:输入要发送的原始正文内容。

¥Body: Enter the raw body content to send.

请参阅你服务的 API 文档以获取详细指南。

¥Refer to your service's API documentation for detailed guidance.

节点选项#

¥Node options

选择“添加选项”以查看和选择这些选项。除非另有说明,所有参数均可使用选项。

¥Select Add Option to view and select these options. Options are available to all parameters unless otherwise noted.

查询中的数组格式参数#

¥Array Format in Query Parameters

Option availability

此选项仅在启用“发送查询参数”时可用。

¥This option is only available when you turn on Send Query Parameters.

使用此选项可控制查询参数中包含的数组的格式。选择以下选项:

¥Use this option to control the format for arrays included in query parameters. Choose from these options:

  • 无括号:数组将以“名称=值”的格式存储,例如:foo=bar&foo=qux

¥No Brackets: Arrays will format as the name=value for each item in the array, for example: foo=bar&foo=qux.

  • 仅括号:该节点会在每个数组名称后添加方括号,例如:foo[]=bar&foo[]=qux

¥Brackets Only: The node adds square brackets after each array name, for example: foo[]=bar&foo[]=qux.

  • 带索引的括号:该节点会在每个数组名称后添加带有索引值的方括号,例如:foo[0]=bar&foo[1]=qux

¥Brackets with Indices: The node adds square brackets with an index value after each array name, for example: foo[0]=bar&foo[1]=qux.

请参阅你服务的 API 文档以获取有关使用哪个选项的指南。

¥Refer to your service's API documentation for guidance on which option to use.

批处理#

¥Batching

控制大量输入项的批处理方式:

¥Control how to batch large numbers of input items:

  • 每批次项目数:请输入每批次包含的输入项数量。

¥Items per Batch: Enter the number of input items to include in each batch.

  • 批处理间隔:输入每批请求之间的等待时间(以毫秒为单位)。输入 0 表示不设置批处理间隔。

¥Batch Interval: Enter the time to wait between each batch of requests in milliseconds. Enter 0 for no batch interval.

忽略 SSL 问题#

¥Ignore SSL Issues

默认情况下,n8n 仅在 SSL 证书验证成功后才会下载响应。如果你希望即使 SSL 证书验证失败也下载响应,请启用此选项。

¥By default, n8n only downloads the response if SSL certificate validation succeeds. If you'd like to download the response even if SSL certificate validation fails, turn this option on.

小写标头#

¥Lowercase Headers

选择是否将邮件头名称转换为小写(已开启,默认)或不转换为小写(已关闭)。

¥Choose whether to lowercase header names (turned on, default) or not (turned off).

重定向#

¥Redirects

选择是否跟随重定向(默认开启)或不跟随重定向(默认关闭)。如果启用此选项,请在“最大重定向次数”中输入请求应遵循的最大重定向次数。

¥Choose whether to follow redirects (turned on by default) or not (turned off). If turned on, enter the maximum number of redirects the request should follow in Max Redirects.

响应#

¥Response

使用此选项可设置预期 API 响应的一些详细信息,包括:

¥Use this option to set some details about the expected API response, including:

  • 包含响应标头和状态:默认情况下,该节点仅返回邮件正文。启用此选项可返回完整的响应(包括响应头和响应状态码)以及响应正文。

¥Include Response Headers and Status: By default, the node returns only the body. Turn this option on to return the full response (headers and response status code) as well as the body.

  • 从不出错:默认情况下,节点仅在响应返回 2xx 代码时才返回成功。启用此选项可确保无论返回的代码如何,都返回成功。

¥Never Error: By default, the node returns success only when the response returns with a 2xx code. Turn this option on to return success regardless of the code returned.

  • 响应格式:选择数据返回的格式。选择以下选项:

¥Response Format: Select the format in which the data gets returned. Choose from:

  • 自动检测(默认):该节点会根据返回的数据检测并格式化响应。

    ¥Autodetect (default): The node detects and formats the response based on the data returned.

  • 文件:选择此选项可将响应保存到文件中。在“将输出放入字段”中,输入要将文件返回到的字段名称。

    ¥File: Select this option to put the response into a file. Enter the field name where you want the file returned in Put Output in Field.

  • JSON:选择此选项可将响应格式化为 JSON。

    ¥JSON: Select this option to format the response as JSON.

  • 文本:选择此选项可将响应格式化为纯文本。在“将输出放入字段”中,输入要将文件返回到的字段名称。

    ¥Text: Select this option to format the response as plain text. Enter the field name where you want the file returned in Put Output in Field.

分页#

¥Pagination

使用此选项可对结果进行分页,这对于处理 API 无法在单次调用中返回的过大查询结果非常有用。

¥Use this option to paginate results, useful for handling query results that are too big for the API to return in a single call.

Inspect the API data first

某些分页选项需要了解你正在使用的 API 返回的数据。在设置分页之前,请查阅 API 文档,或执行一次不分页的 API 调用,以查看其返回的数据。

¥Some options for pagination require knowledge of the data returned by the API you're using. Before setting up pagination, either check the API documentation, or do an API call without pagination, to see the data it returns.

Understand pagination

Pagination means splitting a large set of data into multiple pages. The amount of data on each page depends on the limit you set.

For example, you make an API call to an endpoint called /users. The API wants to send back information on 300 users, but this is too much data for the API to send in one response.

If the API supports pagination, you can incrementally fetch the data. To do this, you call /users with a pagination limit, and a page number or URL to tell the API which page to send. In this example, say you use a limit of 10, and start from page 0. The API sends the first 10 users in its response. You then call the API again, increasing the page number by 1, to get the next 10 results.

配置分页设置:

¥Configure the pagination settings:

  • 分页模式:

¥Pagination Mode:

  • 关闭:关闭分页。

    ¥Off: Turn off pagination.

  • 更新每个请求中的参数:当需要为每个请求动态设置参数时,请使用此选项。

    ¥Update a Parameter in Each Request: Use this when you need to dynamically set parameters for each request.

  • 响应包含下一个 URL:当 API 响应包含下一页的 URL 时,请使用此选项。使用表达式设置下一个 URL。

    ¥Response Contains Next URL: Use this when the API response includes the URL of the next page. Use an expression to set Next URL.

例如,对于设置示例,请参考 HTTP 请求节点 Cookbook | 分页

¥For example setups, refer to HTTP Request node cookbook | Pagination.

n8n 提供内置变量,用于在使用分页时处理 HTTP 节点请求和响应:

¥n8n provides built-in variables for working with HTTP node requests and responses when using pagination:

Variable Description
$pageCount The pagination count. Tracks how many pages the node has fetched.
$request The request object sent by the HTTP node.
$response The response object from the HTTP call. Includes $response.body, $response.headers, and $response.statusCode. The contents of body and headers depend on the data sent by the API.

API differences

Different APIs implement pagination in different ways. Check the API documentation for the API you're using for details. You need to find out things like:

  • Does the API provide the URL for the next page?
  • Are there API-specific limits on page size or page number?
  • The structure of the data that the API returns.

代理#

¥Proxy

如果需要指定 HTTP 代理,请使用此选项。

¥Use this option if you need to specify an HTTP proxy.

输入请求应使用的代理。此设置优先于使用 HTTP_PROXYHTTPS_PROXYALL_PROXY 环境变量 定义的全局设置。

¥Enter the Proxy the request should use. This takes precedence over global settings defined with the HTTP_PROXY, HTTPS_PROXY, or ALL_PROXY environment variables.

超时#

¥Timeout

使用此选项可设置节点等待服务器发送响应头(并开始发送响应正文)的时间。该节点会中止初始响应超过此值的请求。

¥Use this option to set how long the node should wait for the server to send response headers (and start the response body). The node aborts requests that exceed this value for the initial response.

输入等待超时时间(以毫秒为单位)。

¥Enter the Timeout time to wait in milliseconds.

仅限工具选项#

¥Tool-only options

以下选项仅在作为 tool 连接到 AI 代理 时可用。

¥The following options are only available when attached to an AI agent as a tool.

优化响应#

¥Optimize Response

是否优化工具响应以减少传递给 LLM 的数据量。优化响应可以降低成本,并帮助 LLM 忽略不重要的细节,通常能带来更好的结果。

¥Whether to optimize the tool response to reduce the amount of data passed to the LLM. Optimizing the response can reduce costs and can help the LLM ignore unimportant details, often leading to better results.

优化响应时,你需要选择预期响应类型,这将决定你可以配置的其他选项。支持的响应类型如下:

¥When optimizing responses, you select an expected response type, which determines other options you can configure. The supported response types are:

JSON#

预期响应为 JSON 时,你可以使用以下选项配置要用作响应的 JSON 数据部分:

¥When expecting a JSON response, you can configure which parts of the JSON data to use as a response with the following choices:

  • 包含数据的字段:此字段标识 JSON 对象中包含相关数据的特定部分。你可以将其留空以使用完整的响应。

¥Field Containing Data: This field identifies a specific part of the JSON object that contains your relevant data. You can leave this blank to use the entire response.

  • 包含字段:这样你就可以选择要在响应对象中包含哪些字段。有三种选择:

¥Include Fields: This is how you choose which fields you want in your response object. There are three choices:

  • 全部:包含响应对象中的所有字段。

    ¥All: Include all fields in the response object.

  • 已选:仅包含以下指定的字段。

    ¥Selected: Include only the fields specified below.

    • 字段:要包含在响应中的字段列表(以逗号分隔)。你可以使用点号表示法指定嵌套字段。你可以从“输入”面板拖动字段,将其添加到字段列表中。

    ¥Fields: A comma-separated list of fields to include in the response. You can use dot notation to specify nested fields. You can drag fields from the Input panel to add them to the field list.

  • 排除:包含除以下指定字段之外的所有字段。

    ¥Exclude: Include all fields except the fields specified below.

    • 字段:要从响应中排除的字段列表(以逗号分隔)。你可以使用点号表示法指定嵌套字段。你可以从“输入”面板拖动字段,将其添加到字段列表中。

    ¥Fields: A comma-separated list of fields to exclude from the response. You can use dot notation to specify nested fields. You can drag fields from the Input panel to add them to the field list.

HTML#

预期响应为 HTML 时,你可以识别 HTML 文档中与 LLM 相关的部分,并使用以下选项优化响应:

¥When expecting HTML, you can identify the part of an HTML document relevant to the LLM and optimize the response with the following options:

  • 选择器 (CSS):要在响应 HTML 中包含的特定元素或元素类型。默认使用 body 元素。

¥Selector (CSS): A specific element or element type to include in the response HTML. Uses the body element by default.

  • 仅返回内容:是否从响应中移除 HTML 标签和属性,仅保留实际内容。这使用更少的令牌,可能更容易被模型理解。

¥Return Only Content: Whether to strip HTML tags and attributes from the response, leaving only the actual content. This uses fewer tokens and may be easier for the model to understand.

  • 要省略的元素:提取内容时要排除的 CSS 选择器列表(以逗号分隔)。

    ¥Elements To Omit: A comma-separated list of CSS selectors to exclude when extracting content.

  • 截断响应:是否限制响应大小以节省令牌。

¥Truncate Response: Whether to limit the response size to save tokens.

  • 最大响应字符数:HTML 响应中包含的最大字符数。默认值为 1000。

    ¥Max Response Characters: The maximum number of characters to include in the HTML response. The default value is 1000.

文本#

¥Text

预期响应为通用文本时,你可以使用以下选项优化结果:

¥When expecting a generic Text response, you can optimize the results with the following options:

  • 截断响应:是否限制响应大小以节省令牌。

¥Truncate Response: Whether to limit the response size to save tokens.

  • 最大响应字符数:HTML 响应中包含的最大字符数。默认值为 1000。

    ¥Max Response Characters: The maximum number of characters to include in the HTML response. The default value is 1000.

导入 curl 命令#

¥Import curl command

curl 是一个用于通过 URL 传输数据的命令行工具和库。

¥curl is a command line tool and library for transferring data with URLs.

你可以使用 curl 调用 REST API。如果你要使用的服务的 API 文档提供了 curl 示例,你可以将其从文档复制到 n8n 中以配置 HTTP 请求节点。

¥You can use curl to call REST APIs. If the API documentation of the service you want to use provides curl examples, you can copy them out of the documentation and into n8n to configure the HTTP Request node.

导入 curl 命令:

¥Import a curl command:

  1. 在 HTTP 请求节点的“参数”选项卡中,选择“导入 cURL”。打开“导入 cURL 命令”对话框。

¥From the HTTP Request node's Parameters tab, select Import cURL. The Import cURL command modal opens. 2. 将你的 curl 命令粘贴到文本框中。

¥Paste your curl command into the text box. 3. 选择“导入”。n8n 将请求配置加载到节点字段中。此操作会覆盖任何现有配置。

¥Select Import. n8n loads the request configuration into the node fields. This overwrites any existing configuration.

模板和示例#

¥Templates and examples

Template widget placeholder.

常见问题#

¥Common issues

有关常见问题或建议的解决方案,请参阅 常见问题

¥For common questions or issues and suggested solutions, refer to Common Issues.