我正在使用powershell来使用Bitbucket API。Powershell发送命令进行检查,如果可以合并拉请求,然后将其合并。
第一个命令工作时没有任何问题:
Invoke-WebRequest -Headers @{Authorization = "Basic $base64AuthInfo"} -Method Get -ContentType "application/json" -Uri "$BaseUrl/rest/api/1.0/projects/$ProjectKey/repos/$RepoSlug/pull-requests/$PullRequestId/merge?version=$PRVersion"我得到了一个有效的JSON响应。示例:
{"canMerge":true,"conflicted":false,"outcome":"CLEAN","vetoes":[]}第二个命令必须使用POST请求来合并拉请求。与Post而不是Get相同的命令:
Invoke-WebRequest -Headers @{Authorization = "Basic $base64AuthInfo"} -Method Post -ContentType "application/json" -Uri "$BaseUrl/rest/api/1.0/projects/$ProjectKey/repos/$RepoSlug/pull-requests/$PullRequestId/merge?version=$PRVersion" -Verbose这一个返回400错误,没有任何其他信息。
VERBOSE: POST https://bitbucket.example.com/rest/api/1.0/projects/TEAM/repos/tmp-test-repo/pull-requests/8/merge?version=2 with 0-byte payload
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At line:1 char:1
+ Invoke-WebRequest -Headers @{Authorization = "Basic $base64AuthInfo"} ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand如何才能使职位要求工作?
参考资料:Bitbucket文档
发布于 2017-11-03 09:24:09
问题是Powershell没有在Invoke输出中输出扩展的细节,因此这使得调查变得非常困难。结果发现这个问题是我用的。在我使用Fiddler获取响应头之后,我从Bitbucket API获得了一个详细的响应,因此我能够修复我的问题。
https://stackoverflow.com/questions/46935518
复制相似问题