如何在PowerShell中编写类似于curl的等效命令。

huangapple go评论65阅读模式
英文:

how to write equivalent of curl in powershell

问题

以下是翻译好的部分:

The following curl command works in azure cli.

以下curl命令在azure cli中有效。

I have created an equivalent on for powershell on desktop but it fails. What am I doing wrong?

我在桌面上为powershell创建了一个等效的命令,但它失败了。我做错了什么?

curl : {"error":{"code":"404","message": "Resource not found"}}
curl:{"error":{"code":"404","message":"未找到资源"}}
At line:1 char:1
在行:1字符:1

英文:

The following curl command works in 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"}'

I have created an equivalent on for powershell on desktop but it fails. What am I doing wrong?

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

答案1

得分: 5

Powershell提供了一个别名用于“curl”,它实际上是运行invoke-webrequest,这基本上永远不会为您执行正确的操作,而且大多数情况下只会破坏您尝试执行的任何操作。

绕过这种疯狂的简单方法是在命令行上键入curl.exe而不仅仅是curl

Windows 10和11已经多年来捆绑了一个“真正的”curl工具。

英文:

Powershell provides an alias for "curl" that instead makes it run invoke-webrequest which basically never does the right thing for you and will mostly just ruin whatever you try to do.

An easy way to circumvent this craziness is by typing out curl.exe instead of just curl on the command line.

Windows 10 and 11 have shipped a bundled "real" curl tool since several years by now.

huangapple
  • 本文由 发表于 2023年6月1日 15:32:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定