從 Azure Logic Apps 透過 HTTP 或 HTTPS 呼叫服務端點Call service endpoints over HTTP or HTTPS from Azure Logic Apps

使用 Azure Logic Apps 和內建的 HTTP 觸發程式或動作,您可以建立自動化的工作和工作流程,以透過 HTTP 或 HTTPS 將輸出要求傳送至其他服務和系統上的端點。With Azure Logic Apps and the built-in HTTP trigger or action, you can create automated tasks and workflows that can send outbound requests to endpoints on other services and systems over HTTP or HTTPS. 若要改為接收及回應輸入的 HTTPS 呼叫,請使用內建的 要求觸發程式和回應動作To receive and respond to inbound HTTPS calls instead, use the built-in Request trigger and Response action.

例如,您可以藉由檢查特定排程上的端點,來監視網站的服務端點。For example, you can monitor a 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.

  • 若要依週期性排程檢查或 輪詢 端點,請 新增 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.

本文說明如何使用 HTTP 觸發程式和 HTTP 動作,讓您的邏輯應用程式可以將輸出呼叫傳送給其他服務和系統。This article shows how to use the HTTP trigger and HTTP action so that your logic app can send outbound calls to other services and systems.

如需從邏輯應用程式進行輸出呼叫的加密、安全性和授權的相關資訊(例如 傳輸層安全性 (TLS) ,之前稱為安全通訊端層 (SSL) 、自我簽署的憑證,或 Azure Active Directory (的開放驗證 Azure AD ,請參閱 安全存取和資料存取,以存取其他服務和系統的輸出呼叫For information about encryption, security, and authorization for outbound calls from your logic app, such as Transport Layer Security (TLS), previously known as Secure Sockets Layer (SSL), self-signed certificates, or Azure Active Directory Open Authentication (Azure AD OAuth), see Secure access and data - Access for outbound calls to other services and systems.

PrerequisitesPrerequisites

新增 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 觸發程式」,讓步驟有更具描述性的名稱。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 觸發程序參數

    如果您選取 [ ] 以外的驗證類型,則驗證設定會根據您的選取專案而有所不同。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 動作」,讓步驟有更具描述性的名稱。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 動作參數

    如果您選取 [ ] 以外的驗證類型,則驗證設定會根據您的選取專案而有所不同。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.

觸發程式和動作輸出Trigger and action outputs

以下是 HTTP 觸發程式或動作之輸出的詳細資訊,會傳回下列資訊:Here is more information about the outputs from an HTTP trigger or action, which returns this information:

屬性Property 類型Type 描述Description
headers JSON 物件JSON object 要求的標頭The headers from the request
body JSON 物件JSON object 具有來自要求之本文內容的物件The object with the body content from the request
status code 整數Integer 要求的狀態碼The status code from the request
狀態碼Status code 描述Description
200200 [確定]OK
202202 已接受Accepted
400400 不正確的要求Bad request
401401 未經授權Unauthorized
403403 禁止Forbidden
404404 找不到Not Found
500500 內部伺服器錯誤。Internal server error. 發生未知錯誤。Unknown error occurred.

具有多部分/表單資料類型的內容Content with multipart/form-data type

若要處理 multipart/form-data 在 HTTP 要求中具有類型的內容,您可以使用此格式,將包含和屬性的 JSON 物件新增 $content-type $multipart 至 HTTP 要求的主體。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 (支援此類型),將 Excel 檔案的 HTTP POST 要求傳送至網站 multipart/form-dataFor 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"
}

Content with application/x-www-表單 urlencoded 類型Content with application/x-www-form-urlencoded type

若要在主體中提供 urlencoded 的資料給 HTTP 要求,您必須指定資料的 application/x-www-form-urlencoded 內容類型。To provide form-urlencoded data in the body for an HTTP request, you have to specify that the data has the application/x-www-form-urlencoded content type. 在 HTTP 觸發程式或動作中,新增 content-type 標頭。In the HTTP trigger or action, add the content-type header. 將標頭值設定為 application/x-www-form-urlencodedSet the header value to application/x-www-form-urlencoded.

例如,假設您有一個邏輯應用程式,它會將 HTTP POST 要求傳送至支援此類型的網站 application/x-www-form-urlencodedFor example, suppose you have a logic app that sends an HTTP POST request to a website, which supports the application/x-www-form-urlencoded type. 以下是此動作可能的外觀:Here's how this action might look:

顯示「content-type」標頭設定為 ' application/x-www-urlencoded ' 之 HTTP 要求的螢幕擷取畫面

非同步要求-回應行為Asynchronous request-response behavior

根據預設,Azure Logic Apps 中的所有 HTTP 型動作都會遵循標準的 非同步作業模式By default, all HTTP-based actions in Azure Logic Apps follow the standard asynchronous operation pattern. 這個模式會指定在 HTTP 動作呼叫或將要求傳送至端點、服務、系統或 API 之後,接收者會立即傳回「 202 接受 」回應。This pattern specifies that after an HTTP action calls or sends a request to an endpoint, service, system, or API, the receiver immediately returns a "202 ACCEPTED" response. 這段程式碼會確認接收者已接受要求,但尚未完成處理。This code confirms that the receiver accepted the request but hasn't finished processing. 回應可以包含 location 指定 URL 和重新整理識別碼的標頭,呼叫者可以用來輪詢或檢查非同步要求的狀態,直到接收者停止處理並傳回「 200 正常 」成功回應或其他非202回應。The response can include a location header that specifies the URL and a refresh ID that the caller can use to poll or check the status for the asynchronous request until the receiver stops processing and returns a "200 OK" success response or other non-202 response. 不過,呼叫端不需要等待要求完成處理,而且可以繼續執行下一個動作。However, the caller doesn't have to wait for the request to finish processing and can continue to run the next action. 如需詳細資訊,請參閱 非同步微服務整合強制執行微服務自主性For more information, see Asynchronous microservice integration enforces microservice autonomy.

  • 在邏輯應用程式設計工具中,HTTP 動作(而非觸發程式)的 非同步模式 設定預設為啟用。In the Logic App Designer, the HTTP action, but not trigger, has an Asynchronous Pattern setting, which is enabled by default. 這種設定會指定呼叫端不等候處理完成,而且可以繼續執行下一個動作,但會繼續檢查狀態,直到處理停止為止。This setting specifies that the caller doesn't wait for processing to finish and can move on to the next action but continues checking the status until processing stops. 如果停用,則此設定會指定呼叫端等候處理完成,然後再繼續進行下一個動作。If disabled, this setting specifies that the caller waits for processing to finish before moving on to the next action.

    若要尋找此設定,請遵循下列步驟:To find this setting, follow these steps:

    1. 在 HTTP 動作的標題列上,選取省略號 (...) 按鈕,這會開啟動作的設定。On the HTTP action's title bar, select the ellipses (...) button, which opens the action's settings.

    2. 尋找 非同步模式 設定。Find the Asynchronous Pattern setting.

      「非同步模式」設定

  • HTTP 動作的基礎 JavaScript 物件標記法 (JSON) 定義會隱含地遵循非同步作業模式。The HTTP action's underlying JavaScript Object Notation (JSON) definition implicitly follows the asynchronous operation pattern.

停用非同步作業Disable asynchronous operations

有時,您可能會想要在特定情況下,HTTP 動作的非同步行為,例如,當您想要:Sometimes, you might want to the HTTP action's asynchronous behavior in specific scenarios, for example, when you want to:

關閉 非同步模式 設定Turn off Asynchronous Pattern setting

  1. 在邏輯應用程式設計工具的 HTTP 動作標題列上,選取省略號 (...) 按鈕,這會開啟動作的設定。In the Logic App Designer, on the HTTP action's title bar, select the ellipses (...) button, which opens the action's settings.

  2. 尋找 [ 非同步模式 ] 設定,並在啟用時將設定轉換為 [ 關閉 ],然後選取 [ 完成]。Find the Asynchronous Pattern setting, turn the setting to Off if enabled, and select Done.

    停用 [非同步模式] 設定

停用動作的 JSON 定義中的非同步模式Disable asynchronous pattern in action's JSON definition

在 HTTP 動作的基礎 JSON 定義中, 將作業 "DisableAsyncPattern" 選項新增 至動作的定義,讓動作改為遵循同步操作模式。In the HTTP action's underlying JSON definition, add the "DisableAsyncPattern" operation option to the action's definition so that the action follows the synchronous operation pattern instead. 如需詳細資訊,請參閱 在同步操作模式中執行動作For more information, see also Run actions in a synchronous operation pattern.

避免長時間執行之工作的 HTTP 超時Avoid HTTP timeouts for long-running tasks

HTTP 要求有 超時限制HTTP requests have a timeout limit. 如果您有長時間執行的 HTTP 動作,但因為這項限制,您可以使用下列選項:If you have a long-running HTTP action that times out due to this limit, you have these options:

  • 停用 HTTP 動作的非同步作業模式 ,讓動作不會持續輪詢或檢查要求的狀態。Disable the HTTP action's asynchronous operation pattern so that the action doesn't continually poll or check the request's status. 相反地,此動作會等候接收者在要求完成處理之後,回應狀態和結果。Instead, the action waits for the receiver to respond with the status and results after the request finishes processing.

  • Http Webhook 動作取代 HTTP 動作,這會在要求完成處理之後,等候接收者回應狀態和結果。Replace the HTTP action with the HTTP Webhook action, which waits for the receiver to respond with the status and results after the request finishes processing.

停用檢查位置標頭Disable checking location headers

某些端點、服務、系統或 Api 會傳回不含標頭的「202已接受」回應 locationSome endpoints, services, systems, or APIs return a "202 ACCEPTED" response that don't have a location header. 當標頭不存在時,若要避免 HTTP 動作持續檢查要求狀態 location ,您可以使用下列選項:To avoid having an HTTP action continually check the request status when the location header doesn't exist, you can have these options:

  • 停用 HTTP 動作的非同步作業模式 ,讓動作不會持續輪詢或檢查要求的狀態。Disable the HTTP action's asynchronous operation pattern so that the action doesn't continually poll or check the request's status. 相反地,此動作會等候接收者在要求完成處理之後,回應狀態和結果。Instead, the action waits for the receiver to respond with the status and results after the request finishes processing.

  • Http Webhook 動作取代 HTTP 動作,這會在要求完成處理之後,等候接收者回應狀態和結果。Replace the HTTP action with the HTTP Webhook action, which waits for the receiver to respond with the status and results after the request finishes processing.

已知問題Known issues

省略的 HTTP 標頭Omitted HTTP headers

如果 HTTP 觸發程式或動作包含這些標頭,Logic Apps 會將這些標頭從產生的要求訊息中移除,而不會顯示任何警告或錯誤: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-* 標頭除外 Accept-versionAccept-* headers except for Accept-version
  • Allow
  • Content-*``Content-Disposition Content-Encoding Content-Type 當您使用 POST 和 PUT 作業時,可接受、和以外的標頭。Content-* headers except for Content-Disposition, Content-Encoding, and Content-Type, which are honored when you use the POST and PUT operations. 但是,當您使用 GET 作業時,Logic Apps 會卸載這些標頭。However, Logic Apps drops these headers when you use the GET operation.
  • Cookie 標頭,但是 Logic Apps 會接受您使用 Cookie 屬性指定的任何值。Cookie header, but Logic Apps honors any value that you specify using the Cookie property.
  • Expires
  • Host
  • Last-Modified
  • Origin
  • Set-Cookie
  • Transfer-Encoding

雖然 Logic Apps 不會阻止您儲存使用 HTTP 觸發程式或動作與這些標頭的邏輯應用程式,但 Logic Apps 會忽略這些標頭。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.

連接器參考Connector reference

如需有關觸發程式和動作參數的詳細資訊,請參閱下列各節:For more information about trigger and action parameters, see these sections:

下一步Next steps