我在尝试使用PowerShell自动创建新的Git仓库时遇到了难题。
据我所知,通过在URL上使用POST方法创建新的存储库。
但是执行时出现了内部服务器错误(500)。没有更多关于错误原因的详细信息或InnerExceptions。
使用GET检索存储库列表有效,因此身份验证有效(至少对于Get请求)。
根据此,这应该是一个正确的语句:
如果你们中的任何一个天才能指点我正确的方向,那就太好了,因为我刚刚开始使用web服务。
谢谢, 迈克尔
/rest/api/1.0/projects/$ProjectKey/repos
https://developer.atlassian.com/static/rest/stash/3.0.1/stash-rest.html#idp1178320
因为只有管理员才能修改我添加的内容,所以我在 webrequest 中添加了一个授权头字段。
$ByteArr = [System.Text.Encoding]::UTF8.GetBytes('admin:pwd')
$Base64Creds = [Convert]::ToBase64String($ByteArr)
$ProjectKey = 'SBOX'
$CreateRepoUri = "$BaseUri/rest/api/1.0/projects/$ProjectKey/repos/"
Invoke-RestMethod -Method Post `
-Headers @{ Authorization="Basic $Base64Creds" } `
-Uri $CreateRepoUri `
-ContentType 'application/json' `
-Body @{ slug='test'; name='RestCreatedRepo';}
但是执行时出现了内部服务器错误(500)。没有更多关于错误原因的详细信息或InnerExceptions。
使用GET检索存储库列表有效,因此身份验证有效(至少对于Get请求)。
根据此,这应该是一个正确的语句:
- https://answers.atlassian.com/questions/127261/create-project-using-rest
- powershell http post REST API basic authentication
如果你们中的任何一个天才能指点我正确的方向,那就太好了,因为我刚刚开始使用web服务。
谢谢, 迈克尔
$data
时需要使用双重{{
}}
,否则-f将显示无效格式。$data = '{{"name": "{0}","scmId": "git","forkable": true}}' -f $repoName
- Alvaromon