CMD 发送请求到 API
CMD send request to API
如何通过 Windows CMD 向远程 API 发送 HTTP 请求?例如
http://example.com/api/1
会 return 一个 JSON 对象。
我见过一些有用的工具,例如 windows 的 cURL,但如果可能的话,我想避免为此安装任何第 3 方软件。另外,我想要的是发送请求,并将响应保存为 .txt 文件(称之为 resp.txt)
我知道在 powershell 中,window 的命令行工具更好,您可以执行以下操作。
$client = new-object System.Net.WebClient
$client.DownloadFile("http://example.com/anything.here", "C:\tmp\FROMNET.txt")
在命令行中,我认为这是不可能的,除非你安装第 3 方工具
晚了 7 年,但这里有一个纯 CMD 解决方案(需要安装 PowerShell):
powershell -NoLogo -NoProfile -Command (New-Object System.Net.WebClient).DownloadFile('https://www.example.com/foobar', 'C:\path\to\response.json')
如何通过 Windows CMD 向远程 API 发送 HTTP 请求?例如
http://example.com/api/1
会 return 一个 JSON 对象。
我见过一些有用的工具,例如 windows 的 cURL,但如果可能的话,我想避免为此安装任何第 3 方软件。另外,我想要的是发送请求,并将响应保存为 .txt 文件(称之为 resp.txt)
我知道在 powershell 中,window 的命令行工具更好,您可以执行以下操作。
$client = new-object System.Net.WebClient
$client.DownloadFile("http://example.com/anything.here", "C:\tmp\FROMNET.txt")
在命令行中,我认为这是不可能的,除非你安装第 3 方工具
晚了 7 年,但这里有一个纯 CMD 解决方案(需要安装 PowerShell):
powershell -NoLogo -NoProfile -Command (New-Object System.Net.WebClient).DownloadFile('https://www.example.com/foobar', 'C:\path\to\response.json')