網址發現插件

建立開發 Proxy 攔截的 URL 清單。 使用此外掛程式來瞭解您的應用程式所呼叫的 URL,以及如何設定開發 Proxy 來模擬其行為。

提示

若要將摘要儲存至檔案,請在您的設定中使用記者外掛程式。

分割命令提示字元視窗的螢幕快照。在左側,顯示攔截要求的開發 Proxy 輸出。在右側,產生具有攔截 URL 的報告。

組態範例

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.0.0/rc.schema.json",
  "plugins": [
    {
      "name": "UrlDiscoveryPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
    }
  ]
}

組態屬性

沒有

Output

UrlDiscoveryPlugin 會在你停止錄影時產生報告。 報告包含開發代理攔截請求的唯一網址,並依字母順序排列。 每個 URL 都是完整的請求 URL,包含其查詢字串。

若要將報告儲存為 JSON,請在設定中 UrlDiscoveryPlugin 後加入 JsonReporter 。 JsonReporter 會將報告寫入目前工作目錄中命名 UrlDiscoveryPlugin_JsonReporter.jsonc 的檔案。 如果該檔案已經存在,Dev Proxy 會在檔名後加上時間戳,例如 UrlDiscoveryPlugin_JsonReporter_20261105104151.jsonc。

這個檔案是一個帶有註解的 JSON 檔案(JSONC),你可以用它作為開發代理設定中該 urlsToWatch 屬性的起點。 檔案包含說明如何使用通配符及排除 URL 的註解,接著 urlsToWatch 是一個攔截 URL 的陣列:

{
  // Wildcards
  // 
  // You can use wildcards to catch multiple URLs with the same pattern.
  // For example, you can use the following URL pattern to catch all API requests to
  // JSON Placeholder API:
  // 
  // https://jsonplaceholder.typicode.com/*
  // 
  // Excluding URLs
  // 
  // You can exclude URLs with ! to prevent them from being intercepted.
  // For example, you can exclude the URL https://jsonplaceholder.typicode.com/authors
  // by using the following URL pattern:
  // 
  // !https://jsonplaceholder.typicode.com/authors
  // https://jsonplaceholder.typicode.com/*
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/posts",
    "https://jsonplaceholder.typicode.com/users",
    "https://jsonplaceholder.typicode.com/users/1"
  ]
}
屬性 Description
urlsToWatch 字串陣列。 Dev Proxy 在錄製時攔截到的請求唯一網址,依字母順序排序。 這些網址不包含萬用卡

Important

由於檔案包含註解,標準的 JSON 解析器(如 JSON.parse JavaScript 或 jq)無法解析該檔案。 要讀取腳本中的檔案,可以使用支援註解的解析器,例如 like JSON5 或 jsonc-parser npm 套件,或在解析檔案前先去除註解行。

也請參閱

後續步驟