从 Azure 逻辑应用通过 HTTP 或 HTTPS 调用服务终结点Call service endpoints over HTTP or HTTPS from Azure Logic Apps

使用 Azure 逻辑应用和内置 HTTP 触发器或操作,可以创建自动化任务和工作流,通过 HTTP 或 HTTPS 向服务终结点发送请求。With Azure Logic Apps and the built-in HTTP trigger or action, you can create automated tasks and workflows that send requests to service endpoints over HTTP or HTTPS. 例如,可按特定的计划检查网站的服务终结点,从而对该终结点进行监视。For example, you can monitor the service endpoint for your website by checking that endpoint on a specific schedule. 当该终结点上发生特定的事件(例如网站关闭)时,该事件会触发逻辑应用的工作流并运行该工作流中的操作。When the specified event happens at that endpoint, such as your website going down, the event triggers your logic app's workflow and runs the actions in that workflow. 如果要改为接收和响应入站 HTTPS 调用,请使用内置请求触发器或响应操作If you want to receive and respond to inbound HTTPS calls instead, use the built-in Request trigger or Response action.

Note

根据目标终结点的功能,HTTP 连接器支持传输层安全性 (TLS) 版本 1.0、1.1 和 1.2。Based the target endpoint's capability, the HTTP connector supports Transport Layer Security (TLS) versions 1.0, 1.1, and 1.2. 逻辑应用通过使用可能支持的最高版本与终结点协商。Logic Apps negotiates with the endpoint over using the highest supported version possible. 例如,如果终结点支持 1.2 版,则连接器首先使用 1.2 版。So for example, if the endpoint supports 1.2, the connector uses 1.2 first. 否则,连接器将使用下一个受支持的最高版本。Otherwise, the connector uses the next highest supported version.

HTTP 连接器不支持使用中间 TLS/SSL 证书进行身份验证。The HTTP connector doesn't support intermediate TLS/SSL certificates for authentication.

若要按定期计划检查或轮询某个终结点,可添加 HTTP 触发器作为工作流中的第一个步骤**。To check or poll an endpoint on a recurring schedule, add the HTTP trigger as the first step in your workflow. 每次触发器检查终结点时,触发器都会调用该终结点或向该终结点发送请求**。Each time that the trigger checks the endpoint, the trigger calls or sends a request to the endpoint. 该终结点的响应确定了逻辑应用的工作流是否运行。The endpoint's response determines whether your logic app's workflow runs. 触发器将终结点响应中的任何内容传递到逻辑应用中的操作。The trigger passes any content from the endpoint's response to the actions in your logic app.

若要从工作流中的任何其他位置调用终结点,请添加 HTTP 操作To call an endpoint from anywhere else in your workflow, add the HTTP action. 该终结点的响应确定了工作流剩余操作的运行方式。The endpoint's response determines how your workflow's remaining actions run.

Important

如果 HTTP 触发器或操作包含这些标头,则逻辑应用会从生成的请求消息中删除这些标头,且不显示任何警告或错误:If an HTTP trigger or action includes these headers, Logic Apps removes these headers from the generated request message without showing any warning or error:

  • Accept-*
  • Allow
  • Content-* 中含以下例外:Content-DispositionContent-EncodingContent-TypeContent-* with these exceptions: Content-Disposition, Content-Encoding, and Content-Type
  • Cookie
  • Expires
  • Host
  • Last-Modified
  • Origin
  • Set-Cookie
  • Transfer-Encoding

尽管逻辑应用不会阻止保存此类逻辑应用(使用具有这些标头的 HTTP 触发器或操作的逻辑应用),但逻辑应用会忽略这些标头。Although Logic Apps won't stop you from saving logic apps that use an HTTP trigger or action with these headers, Logic Apps ignores these headers.

本文演示如何将 HTTP 触发器或操作添加到逻辑应用的工作流。This article shows how to add an HTTP trigger or action to your logic app's workflow.

先决条件Prerequisites

添加 HTTP 触发器Add an HTTP trigger

此内置触发器对终结点的指定 URL 发出 HTTP 调用,并返回响应。This built-in trigger makes an HTTP call to the specified URL for an endpoint and returns a response.

  1. 登录到 Azure 门户Sign in to the Azure portal. 在逻辑应用设计器中打开空白逻辑应用。Open your blank logic app in Logic App Designer.

  2. 在设计器的搜索框下,选择“内置”****。Under the designer's search box, select Built-in. 在搜索框中,输入 http 作为筛选器。In the search box, enter http as your filter. 在“触发器”列表中,选择“HTTP”触发器。**** ****From the Triggers list, select the HTTP trigger.

    选择 HTTP 触发器

    此示例将触发器重命名为“HTTP trigger”,使步骤的名称更具描述性。This example renames the trigger to "HTTP trigger" so that the step has a more descriptive name. 此外,该示例稍后会添加 HTTP 操作,因此,两个名称必须唯一。Also, the example later adds an HTTP action, and both names must be unique.

  3. 提供要包含在目标终结点调用中的 HTTP 触发器参数的值。Provide the values for the HTTP trigger parameters that you want to include in the call to the target endpoint. 设置重复周期,以确定触发器检查目标终结点的频率。Set up the recurrence for how often you want the trigger to check the target endpoint.

    输入 HTTP 触发器参数

    如果选择的身份验证类型不是“None”****,则身份验证设置将根据你的选择而有所不同。If you select an authentication type other than None, the authentication settings differ based on your selection. 有关 HTTP 可用的身份验证类型的详细信息,请参阅以下主题:For more information about authentication types available for HTTP, see these topics:

  4. 若要添加其他可用参数,请打开“添加新参数”列表,并选择所需的参数。****To add other available parameters, open the Add new parameter list, and select the parameters that you want.

  5. 继续使用触发器激发时运行的操作生成逻辑应用的工作流。Continue building your logic app's workflow with actions that run when the trigger fires.

  6. 完成后,请记得保存逻辑应用。When you're done, remember to save your logic app. 在设计器工具栏上选择“保存”。****On the designer toolbar, select Save.

添加 HTTP 操作Add an HTTP action

此内置操作对终结点的指定 URL 发出 HTTP 调用,并返回响应。This built-in action makes an HTTP call to the specified URL for an endpoint and returns a response.

  1. 登录到 Azure 门户Sign in to the Azure portal. 在逻辑应用设计器中打开逻辑应用。Open your logic app in Logic App Designer.

    此示例的第一步是使用 HTTP 触发器。This example uses the HTTP trigger as the first step.

  2. 在要添加 HTTP 操作的步骤下,选择“新建步骤”。****Under the step where you want to add the HTTP action, select New step.

    若要在步骤之间添加操作,请将鼠标指针移到步骤之间的箭头上。To add an action between steps, move your pointer over the arrow between steps. 选择出现的加号 ( + ),然后选择“添加操作”。****Select the plus sign (+) that appears, and then select Add an action.

  3. 在“选择操作”下,选择“内置”。**** ****Under Choose an action, select Built-in. 在搜索框中,输入 http 作为筛选器。In the search box, enter http as your filter. 在“操作”列表中,选择“HTTP”操作。**** ****From the Actions list, select the HTTP action.

    选择“HTTP”操作

    此示例将操作重命名为“HTTP action”,使步骤的名称更具描述性。This example renames the action to "HTTP action" so that the step has a more descriptive name.

  4. 提供要包含在目标终结点调用中的 HTTP 操作参数的值。Provide the values for the HTTP action parameters that you want to include in the call to the target endpoint.

    输入 HTTP 操作参数

    如果选择的身份验证类型不是“None”****,则身份验证设置将根据你的选择而有所不同。If you select an authentication type other than None, the authentication settings differ based on your selection. 有关 HTTP 可用的身份验证类型的详细信息,请参阅以下主题:For more information about authentication types available for HTTP, see these topics:

  5. 若要添加其他可用参数,请打开“添加新参数”列表,并选择所需的参数。****To add other available parameters, open the Add new parameter list, and select the parameters that you want.

  6. 完成后,请记得保存逻辑应用。When you're done, remember to save your logic app. 在设计器工具栏上选择“保存”。****On the designer toolbar, select Save.

具有多部分/表单数据类型的内容Content with multipart/form-data type

若要处理 HTTP 请求中具有 multipart/form-data 类型的内容,可以使用此格式向 HTTP 请求的正文添加包含 $content-type$multipart 属性的 JSON 对象。To handle content that has multipart/form-data type in HTTP requests, you can add a JSON object that includes the $content-type and $multipart attributes to the HTTP request's body by using this format.

"body": {
   "$content-type": "multipart/form-data",
   "$multipart": [
      {
         "body": "<output-from-trigger-or-previous-action>",
         "headers": {
            "Content-Disposition": "form-data; name=file; filename=<file-name>"
         }
      }
   ]
}

例如,假设你有一个逻辑应用,它使用该站点的 API(支持 multipart/form-data 类型)向网站发送对 Excel 文件的 HTTP POST 请求。For example, suppose you have a logic app that sends an HTTP POST request for an Excel file to a website by using that site's API, which supports the multipart/form-data type. 下面是此操作的可能外观:Here's how this action might look:

多部分表单数据

以下是在基础工作流定义中显示 HTTP 操作的 JSON 定义的同一示例:Here is the same example that shows the HTTP action's JSON definition in the underlying workflow definition:

"HTTP_action": {
   "inputs": {
      "body": {
         "$content-type": "multipart/form-data",
         "$multipart": [
            {
               "body": "@trigger()",
               "headers": {
                  "Content-Disposition": "form-data; name=file; filename=myExcelFile.xlsx"
               }
            }
         ]
      },
      "method": "POST",
      "uri": "https://finance.contoso.com"
   },
   "runAfter": {},
   "type": "Http"
}

连接器参考Connector reference

有关触发器和操作参数的详细信息,请参阅以下部分:For more information about trigger and action parameters, see these sections:

输出详细信息Output details

下面是有关 HTTP 触发器或操作的输出的详细信息,输出中将返回以下信息:Here is more information about the outputs from an HTTP trigger or action, which returns this information:

属性名称Property name 类型Type 说明Description
headersheaders objectobject 请求中的标头The headers from the request
bodybody objectobject JSON 对象JSON object 包含请求中正文内容的对象The object with the body content from the request
状态代码status code intint 请求中的状态代码The status code from the request
状态代码Status code 说明Description
200200 OKOK
202202 已接受Accepted
400400 错误的请求Bad request
401401 未授权Unauthorized
403403 禁止Forbidden
404404 未找到Not Found
500500 内部服务器错误。Internal server error. 发生未知错误。Unknown error occurred.

后续步骤Next steps