共用方式為


傳回二進位數據的模擬回應

對於某些要求,您可能會想要回應二進位數據,例如檔或影像。

在 Dev Proxy 中,您可以將 設定 response.body 為字串值,其開頭 @ 為 ,後面接著相對於目前工作目錄的檔案路徑,例如:

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/mockresponseplugin.schema.json",
  "mocks": [
    {
      "request": {
        "url": "https://graph.microsoft.com/v1.0/users/*/photo/$value",
        "method":  "GET"
      },
      "response": {
        "body": "@picture.jpg",
        "headers": [
          {
            "name": "content-type",
            "value": "image/jpeg"
          }
        ]
      }
    }
  ]
}

當您呼叫 GET https://graph.microsoft.com/v1.0/users/ben@contoso.com/photo/$value時,您會取得儲存在目前目錄中檔案中的 picture.jpg 映像。

警告

如果您使用命令行來執行 HTTP 要求,請確定您已正確逸出 dollar 簽署。 請參閱 為什麼 Proxy 不會模擬我的二進位回應

後續步驟

深入瞭解MockResponsePlugin。

範例

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