模拟第 n 个请求

开发代理支持通请求对象上的 nth 属性模拟 n 次。

小窍门

通过在命令提示符 devproxy config get microsoft-graph-connector中运行来下载此预设。

将以下模拟文件用作示例,可以看到它包含对同一请求 URL 的两个模拟。 当第二次截获具有指定 URL 的请求时,代理使用首次包含nth属性的响应。 对于所有其他请求,代理将返回第二个响应。

小窍门

应先使用 nth 属性进行模拟。 代理根据第一个匹配项使用模拟。

{
  "$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。

示例

另请参阅相关的开发代理示例: