共用方式為


模擬第 n 個要求

Dev Proxy 支援透過nth要求物件上的 屬性模擬 n 次。

小提示

在命令提示字元中執行 devproxy config get microsoft-graph-connector以下載此預設。

使用下列範例檔案,我們可以看到它包含兩個指向相同要求 URL 的模擬配置。 Proxy 將在第二次攔截具有指定 URL 的請求時,使用含有 nth 屬性的首次回應。 對於所有其他要求,Proxy 會傳回第二個回應。

小提示

使用 nth 屬性的模擬應當優先。 Proxy 會根據第一個相符條件使用模擬物件。

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/mockresponseplugin.schema.json",
  "mocks": [
    {
      "request": {
        "url": "https://graph.microsoft.com/v1.0/external/connections/*/operations/*",
        "method": "GET",
        "nth": 2
      },
      "response": {
        "statusCode": 200,
        "body": {
          "id": "1.neu.0278337E599FC8DBF5607ED12CF463E4.6410CCF8F6DB8758539FB58EB56BF8DC",
          "status": "completed",
          "error": null
        }
      }
    },
    {
      "request": {
        "url": "https://graph.microsoft.com/v1.0/external/connections/*/operations/*",
        "method": "GET"
      },
      "response": {
        "statusCode": 200,
        "body": {
          "id": "1.neu.0278337E599FC8DBF5607ED12CF463E4.6410CCF8F6DB8758539FB58EB56BF8DC",
          "status": "inprogress",
          "error": null
        }
      }
    }
  ]
}

後續步驟

深入瞭解MockResponsePlugin。

範例

另請參閱相關的開發 Proxy 範例: