powershell:bitbucket api post请求返回400错误

时间:2017-10-25 14:47:34

标签: rest powershell bitbucket-api

我正在使用PowerShell来处理Bitbucket API。如果pull请求可以合并然后合并它,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请求才能合并拉取请求。使用发布而不是获取

的命令相同
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

如何使POST请求有效?

参考:Bitbucket documentation

1 个答案:

答案 0 :(得分:0)

问题是Powershell没有在Invoke-WebRequest输出中输出扩展的细节,所以这使调查变得非常困难。 原来这个问题是我正在使用的问题。在我使用Fiddler获取响应头之后,我得到了Bitbucket API的详细响应,因此我能够解决我的问题。

相关问题