0

我正在尝试使用TeamForge API。这是我第一次涉足网络请求,所以我确信我遗漏了一些明显的东西。

甚至开始,我意识到我需要请求一个 oauth 令牌。根据文档,我必须执行以下命令:

# Base URL of TeamForge site.
site_url="https://teamforge.example.com"

# TeamForge authentication credentials.
username="foo"
password="bar"

# Requested scope (all)
scope="urn:ctf:services:ctf urn:ctf:services:svn urn:ctf:services:gerrit urn:ctf:services:soap60"

curl -d "grant_type=password&client_id=api-client&scope=$scope&username=$username&password=$password" $site_url/oauth/auth/token

看起来相当简单。知道这curl是 的别名Invoke-WebRequest,我尝试在 PowerShell 中运行以下命令:

$site="https://my.teamforge.site"
$user="myuser"
$pass="mypass"
$scope="urn:ctf:services:ctf"
curl "grant_type=password&client_id=api-client&scope=$scope&username=$user&password=$pass" -Uri $site/oauth/auth/token

我得到的是一个错误:

Invoke-WebRequest :找不到接受参数 'grant_type=password&client_id=api-client&scope=urn:ctf:services:ctf&username=其余行已编辑的位置参数,原因很明显

我认为这意味着我捏造了语法。我不知道从哪里开始使用此设备并将其插入Invoke-WebRequest命令。就像我说的,这是我第一次尝试这个。到目前为止,我对答案的搜索没有帮助。我想我问错了问题。

如何解构此curl命令,以便将其转换为可在 PowerShell 中使用的内容?

4

0 回答 0