使用 Azure Data Factory 或 Azure Synapse Analytics 從 HTTP 端點複製資料

適用于: Azure Data Factory Azure Synapse Analytics

提示

試用 Microsoft Fabric 中的 Data Factory,這是適用于企業的單一分析解決方案。 Microsoft Fabric 涵蓋從資料移動到資料科學、即時分析、商業智慧和報告等所有專案。 瞭解如何 免費啟動新的試用版

本文概述如何使用 Azure Data Factory 和 Azure Synapse 中的複製活動,從 HTTP 端點複製資料。 本文是以複製活動 為基礎 ,其呈現複製活動的一般概觀。

此 HTTP 連接器、 REST 連接器 Web 資料表連接器 之間的差異如下:

  • REST 連接器 特別支援從 RESTful API 複製資料;
  • HTTP 連接器 是一般,可從任何 HTTP 端點擷取資料,例如下載檔案。 在 REST 連接器可供使用之前,您可能會碰巧使用 HTTP 連接器從 RESTful API 複製資料,相較于 REST 連接器,其支援但功能較少。
  • Web 資料表連接器從 HTML 網頁擷取資料表內容。

支援的功能

下列功能支援此 HTTP 連接器:

支援的功能 IR
複製活動 (source/-) ① ②
查閱活動 ① ②

(1) Azure 整合執行時間 (2) 自我裝載整合執行時間

如需支援作為來源/接收的資料存放區清單,請參閱 支援的資料存放區

您可以使用此 HTTP 連接器來:

提示

若要在設定 HTTP 連接器之前測試資料擷取的 HTTP 要求,請瞭解標頭和本文需求的 API 規格。 您可以使用 Postman 或網頁瀏覽器等工具來驗證。

必要條件

如果您的資料存放區位於內部部署網路、Azure 虛擬網路或 Amazon Virtual Private Cloud 內,您必須設定 自我裝載整合執行時間 以連線到它。

如果您的資料存放區是受控雲端資料服務,您可以使用 Azure Integration Runtime。 如果存取僅限於防火牆規則中核准的 IP,您可以將 Azure Integration Runtime IP 新增 至允許清單。

您也可以使用 Azure Data Factory 中的受控虛擬網路整合執行時間 功能來存取內部部署網路,而不需安裝及設定自我裝載整合執行時間。

如需 Data Factory 所支援之網路安全性機制和選項的詳細資訊,請參閱 資料存取策略

開始使用

若要使用管線執行複製活動,您可以使用下列其中一個工具或 SDK:

使用 UI 建立 HTTP 來源的連結服務

使用下列步驟,在 Azure 入口網站 UI 中建立 HTTP 來源的連結服務。

  1. 流覽至 Azure Data Factory 或 Synapse 工作區中的 [管理] 索引標籤,然後選取 [連結服務],然後按一下 [新增]:

  2. 搜尋 HTTP 並選取 HTTP 連接器。

    Screenshot of the HTTP connector.

  3. 設定服務詳細資料、測試連線,並建立新的連結服務。

    Screenshot of configuration for an HTTP linked service.

連線or 組態詳細資料

下列各節提供屬性的詳細資料,您可以用來定義 HTTP 連接器專屬的實體。

連結的服務屬性

HTTP 連結服務支援下列屬性:

屬性 描述 必要
type type 屬性必須設定為 HttpServer Yes
URL 網頁伺服器的基底 URL。 Yes
enableServerCertificateValidation 指定當您連線到 HTTP 端點時,是否要啟用伺服器 TLS/SSL 憑證驗證。 如果您的 HTTPS 伺服器使用自我簽署憑證,請將此屬性設定為 false No
(預設值為 true
authenticationType 指定驗證類型。 允許的值為 Anonymous Basic Digest Windows ClientCertificate 。 您也可以在 屬性中 authHeader 另外設定驗證標頭。 如需這些驗證類型的更多屬性和 JSON 範例,請參閱下表後面的各節。 Yes
authHeaders 用於驗證的其他 HTTP 要求標頭。
例如,若要使用 API 金鑰驗證,您可以將驗證類型選取為 「匿名」,並在標頭中指定 API 金鑰。
No
connectVia 用來 連接到資料存放區的 Integration Runtime 。 請從 必要條件一 節深入瞭解。 如果未指定,則會使用預設的 Azure Integration Runtime。 No

使用基本、摘要或Windows 驗證

將 authenticationType 屬性設定為 [基本 ]、 [摘要 ] 或 [Windows ]。 除了上一節所述的泛型屬性之外,還指定下列屬性:

屬性 描述 必要
userName 用來存取 HTTP 端點的使用者名稱。 Yes
password 使用者的密碼( userName 值)。 將此欄位標示為 SecureString 類型,以安全地儲存它。 您也可以 參考儲存在 Azure 金鑰保存庫 中的秘密。 Yes

範例

{
    "name": "HttpLinkedService",
    "properties": {
        "type": "HttpServer",
        "typeProperties": {
            "authenticationType": "Basic",
            "url" : "<HTTP endpoint>",
            "userName": "<user name>",
            "password": {
                "type": "SecureString",
                "value": "<password>"
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

使用 ClientCertificate 驗證

若要使用 ClientCertificate 驗證,請將 authenticationType 屬性設定為 ClientCertificate 。 除了上一節所述的泛型屬性之外,還指定下列屬性:

屬性 描述 必要
embeddedCertData Base64 編碼的憑證資料。 指定 embeddedCertData certThumbprint
certThumbprint 安裝在自我裝載 Integration Runtime 機器憑證存放區的憑證指紋。 只有在 connectVia 屬性中 指定 Integration Runtime 的自我裝載類型時,才會套用。 指定 embeddedCertData certThumbprint
password 與憑證相關聯的密碼。 將此欄位標示為 SecureString 類型,以安全地儲存它。 您也可以 參考儲存在 Azure 金鑰保存庫 中的秘密。 No

如果您使用 certThumbprint 進行驗證,且憑證會安裝在本機電腦的個人存放區中,請將讀取權限授與自我裝載整合執行時間:

  1. 開啟 Microsoft Management Console (MMC)。 新增以本機 電腦 為目標的 憑證 嵌入式管理單元。
  2. 展開 [ 憑證 > 個人 ],然後選取 [ 憑證]。
  3. 以滑鼠右鍵按一下個人存放區的憑證,然後選取 [ 所有工作 > 管理私密金鑰]。
  4. 在 [ 安全性] 索引標籤上,新增整合執行時間主機服務 (DIAHostService) 執行所在的使用者帳戶,並具有憑證的讀取權限。
  5. HTTP 連接器只會載入受信任的憑證。 如果您使用自我簽署或未整合的 CA 簽發憑證,若要啟用信任,則憑證也必須安裝在下列其中一個存放區中:
    • 受信任的人員
    • 協力廠商根憑證授權單位
    • 受信任的根憑證授權單位

範例 1:使用 certThumbprint

{
    "name": "HttpLinkedService",
    "properties": {
        "type": "HttpServer",
        "typeProperties": {
            "authenticationType": "ClientCertificate",
            "url": "<HTTP endpoint>",
            "certThumbprint": "<thumbprint of certificate>"
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

範例 2:使用 embeddedCertData

{
    "name": "HttpLinkedService",
    "properties": {
        "type": "HttpServer",
        "typeProperties": {
            "authenticationType": "ClientCertificate",
            "url": "<HTTP endpoint>",
            "embeddedCertData": "<Base64-encoded cert data>",
            "password": {
                "type": "SecureString",
                "value": "password of cert"
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

使用驗證標頭

此外,您可以設定驗證的要求標頭以及內建的驗證類型。

範例:使用 API 金鑰驗證

{
    "name": "HttpLinkedService",
    "properties": {
        "type": "HttpServer",
        "typeProperties": {
            "url": "<HTTP endpoint>",
            "authenticationType": "Anonymous",
            "authHeader": {
                "x-api-key": {
                    "type": "SecureString",
                    "value": "<API key>"
                }
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

資料集屬性

如需可用來定義資料集之區段和屬性的完整清單,請參閱 資料集 一文。

Azure Data Factory 支援下列檔案格式。 如需以格式為基礎的設定,請參閱每個文章。

在格式型資料集的設定下 location ,HTTP 支援下列屬性:

屬性 描述 必要
type 資料集底下的 location type 屬性必須設定為 HttpServerLocation Yes
relativeUrl 包含資料的資源的相對 URL。 HTTP 連接器會從合併的 URL 複製資料: [URL specified in linked service][relative URL specified in dataset] No

注意

支援的 HTTP 要求承載大小約為 500 KB。 如果您想要傳遞至 Web 端點的承載大小大於 500 KB,請考慮以較小的區塊批次處理承載。

範例:

{
    "name": "DelimitedTextDataset",
    "properties": {
        "type": "DelimitedText",
        "linkedServiceName": {
            "referenceName": "<HTTP linked service name>",
            "type": "LinkedServiceReference"
        },
        "schema": [ < physical schema, optional, auto retrieved during authoring > ],
        "typeProperties": {
            "location": {
                "type": "HttpServerLocation",
                "relativeUrl": "<relative url>"
            },
            "columnDelimiter": ",",
            "quoteChar": "\"",
            "firstRowAsHeader": true,
            "compressionCodec": "gzip"
        }
    }
}

複製活動屬性

本節提供 HTTP 來源所支援的屬性清單。

如需可用來定義活動的區段和屬性完整清單,請參閱 管線

HTTP 作為來源

Azure Data Factory 支援下列檔案格式。 如需以格式為基礎的設定,請參閱每個文章。

在格式型複製來源的設定下 storeSettings ,HTTP 支援下列屬性:

屬性 描述 必要
type 底下的 storeSettings type 屬性必須設定為 HttpRead設定 Yes
requestMethod HTTP 方法。
允許的值為 Get (預設值) 和 Post
No
additionalHeaders 其他 HTTP 要求標頭。 No
requestBody HTTP 要求的本文。 No
HTTPRequestTimeout HTTP 要求取得回應的逾時 ( TimeSpan 值)。 此值是取得回應的逾時,而不是讀取回應資料的逾時。 預設值為 00:01:40 No
maxConcurrent連線ions 在活動執行期間,與資料存放區建立的並行連線上限。 只有在您想要限制並行連線時,才指定值。 No

範例:

"activities":[
    {
        "name": "CopyFromHTTP",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<Delimited text input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "DelimitedTextSource",
                "formatSettings":{
                    "type": "DelimitedTextReadSettings",
                    "skipLineCount": 10
                },
                "storeSettings":{
                    "type": "HttpReadSettings",
                    "requestMethod": "Post",
                    "additionalHeaders": "<header key: header value>\n<header key: header value>\n",
                    "requestBody": "<body for POST HTTP request>"
                }
            },
            "sink": {
                "type": "<sink type>"
            }
        }
    }
]

查閱活動屬性

若要瞭解屬性的詳細資料,請檢查 查閱活動

舊版模型

注意

目前仍支援下列模型,以提供回溯相容性。 建議您使用上述各節中提到的新模型,而撰寫 UI 已切換為產生新的模型。

舊版資料集模型

屬性 描述 必要
type 資料集的 type 屬性必須設定為 HttpFile Yes
relativeUrl 包含資料的資源的相對 URL。 未指定此屬性時,只會使用連結服務定義中指定的 URL。 No
requestMethod HTTP 方法。 允許的值為 Get (預設值) 和 Post No
additionalHeaders 其他 HTTP 要求標頭。 No
requestBody HTTP 要求的本文。 No
format 如果您想要依目前方式從 HTTP 端點擷取資料,而不加以剖析,然後將資料複製到以檔案為基礎的存放區,請略過 輸入和輸出資料集定義中的 format 區段。

如果您想要在複製期間剖析 HTTP 回應內容,則支援下列檔案格式類型: TextFormat JsonFormat AvroFormat OrcFormat ParquetFormat 。 在 [格式] 底 下,將 type 屬性設定為下列其中一個 值。 如需詳細資訊,請參閱 JSON 格式、 文字格式 Avro 格式 Orc 格式 Parquet 格式
No
壓縮 指定資料的壓縮類型和層級。 如需詳細資訊,請參閱 支援的檔案格式和壓縮編解碼器

支援的類型:GZip、 Deflate BZip2 ZipDeflate
支援的層級: 最佳 最快
No

注意

支援的 HTTP 要求承載大小約為 500 KB。 如果您想要傳遞至 Web 端點的承載大小大於 500 KB,請考慮以較小的區塊批次處理承載。

範例 1:使用 Get 方法 (預設值)

{
    "name": "HttpSourceDataInput",
    "properties": {
        "type": "HttpFile",
        "linkedServiceName": {
            "referenceName": "<HTTP linked service name>",
            "type": "LinkedServiceReference"
        },
        "typeProperties": {
            "relativeUrl": "<relative url>",
            "additionalHeaders": "Connection: keep-alive\nUser-Agent: Mozilla/5.0\n"
        }
    }
}

範例 2:使用 Post 方法

{
    "name": "HttpSourceDataInput",
    "properties": {
        "type": "HttpFile",
        "linkedServiceName": {
            "referenceName": "<HTTP linked service name>",
            "type": "LinkedServiceReference"
        },
        "typeProperties": {
            "relativeUrl": "<relative url>",
            "requestMethod": "Post",
            "requestBody": "<body for POST HTTP request>"
        }
    }
}

舊版複製活動來源模型

屬性 描述 必要
type 複製 活動來源的 type 屬性必須設定為 HttpSource Yes
HTTPRequestTimeout HTTP 要求取得回應的逾時 ( TimeSpan 值)。 此值是取得回應的逾時,而不是讀取回應資料的逾時。 預設值為 00:01:40 No

範例

"activities":[
    {
        "name": "CopyFromHTTP",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<HTTP input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "HttpSource",
                "httpRequestTimeout": "00:01:00"
            },
            "sink": {
                "type": "<sink type>"
            }
        }
    }
]

如需複製活動支援做為來源和接收的資料存放區清單,請參閱 支援的資料存放區和格式