我试图做与Bibucket API解释完全相同的事情
BitBucket表示/解释
https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html
得到https://api.bitbucket.org/2.0/repositories/{所有者}/{repo_slug}
{
"scm": "hg",
"has_wiki": true,
"description": "Site for tutorial101 files",
"links": {
"watchers": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/watchers"
},
"commits": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/commits"
},
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org"
},
"html": {
"href": "https://bitbucket.org/tutorials/tutorials.bitbucket.org"
},
"avatar": {
"href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2012/Nov/28/tutorials.bitbucket.org-logo-1456883302-9_avatar.png"
},
"forks": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/forks"
},
"clone": [{
"href": "https://bitbucket.org/tutorials/tutorials.bitbucket.org",
"name": "https"
}, {
"href": "ssh://hg@bitbucket.org/tutorials/tutorials.bitbucket.org",
"name": "ssh"
}],
"pullrequests": {
"href": "https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/pullrequests"
}
},
"fork_policy": "allow_forks",
"name": "tutorials.bitbucket.org",
"language": "html/css",
"created_on": "2011-12-20T16:35:06.480042+00:00",
"full_name": "tutorials/tutorials.bitbucket.org",
"has_issues": true,
"owner": {
"username": "tutorials",
"display_name": "tutorials account",
"uuid": "{c788b2da-b7a2-404c-9e26-d3f077557007}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/tutorials"
},
"html": {
"href": "https://bitbucket.org/tutorials"
},
"avatar": {
"href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Nov/25/tutorials-avatar-1563784409-6_avatar.png"
}
}
},
"updated_on": "2014-11-03T02:24:08.409995+00:00",
"size": 76182262,
"is_private": false,
"uuid": "{9970a9b6-2d86-413f-8555-da8e1ac0e542}"
}
我想通过使用powershell来做完全相同的事情。
所以,我做了一个代码。
$username = ""
$password = ""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$response=Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://bitbucket.org/susco/azuretoquickbase -Method Get
$response
我确信我可以登录比特桶,因为我看到了"$response"的内容。
然后,正如Bitbucket所说,我添加了这样的代码来回显Json文件。
$username = ""
$password = ""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$response=Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://bitbucket.org/susco/azuretoquickbase -Method Get
$response
$json = $response.Content|ConvertFrom-Json
$json.data.summaries
但它导致错误
ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
At line:11 char:27
+ $json = $response.Content|ConvertFrom-Json
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertFrom-Json], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
重点是,我确信我可以登录并访问bitbucket所说的页面,但它不会得到json文件和null错误。
我想完全像Bitbuckets页面一样回声,我该怎么做?
Invoke-RestMethod
自动将JSON结果转换为对象。如果只想要原始结果,请使用Invoke-WebRequest
并获取内容属性。
或者在您的情况下,由于您似乎想要该对象,只需使用$json = Invoke-RestMethod ...
。