如何在powershell中编写curl的等效项

Man*_*dha 1 powershell curl

以下curl命令适用于azure cli.

curl https://aoai-try-mc.openai.azure.com/openai/deployments/try-davinci/completions?api-version=2022-12-01 -H "Content-Type:application/json" -H "api-key:keygoeshere" -d '{"prompt":"Tell me a funny story"}'
Run Code Online (Sandbox Code Playgroud)

我已经在桌面上创建了一个等效的 for powershell,但它失败了。我究竟做错了什么?

PS C:\Users\manuchadha> curl https://aoai-try-mc.openai.azure.com/openai/deployments/try-davinci/completions?api-version=2022-12-01 -H @{"Content-Type"="application/json" ; "api-key"="keygoeshere"} -Body @{"prompt"="Tell me a funny story"}
curl : {"error":{"code":"404","message": "Resource not found"}}
At line:1 char:1
+ curl https://aoai-try-mc.openai.azure.com/openai/deployments/try-davi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Run Code Online (Sandbox Code Playgroud)

Dan*_*erg 5

Powershell 为“curl”提供了一个别名,让它运行,invoke-webrequest但它基本上永远不会为您做正确的事情,而且只会毁掉您尝试做的任何事情。

避免这种疯狂的一个简单方法是通过键入而curl.exe不是仅仅curl在命令行上。

几年前,Windows 10 和 11 就已经提供了捆绑的“真正的”curl 工具。