2016-04-18 32 views
0

我在使用GFS檢索樹的TFS Rest API時遇到問題。使用TFS Git Rest api檢索樹時遇到問題

相關的代碼是

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" 
$headers.Add("Accept", 'application/zip') 
$DownloadTreeCmd = "http://tfs.mycompany.com:8080/tfs/myCollection/_apis/git/repositories/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx/trees/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?api-version=1.0&filename=TempDownload.zip&recursive=1" 

$nresp = Invoke-RestMethod $DownloadTreeCmd -UseDefaultCredentials -Headers $headers 

我結束了在$ nrest,我不能讀的東西。我試過把它寫入一個文件,但它不被識別爲一個zip文件。我可以看到我的數據似乎是二進制數據。

我該如何處理這些數據。

回答

0

它的工作,但我不能解釋爲什麼它不工作。

我得到了這個工作,但我不知道我明白這一點。 uri上的filename參數看起來沒有任何作用。返回的對象不能保存到.zip類型的文件中(實際上可以保存,但zip不能將其識別爲存檔)。

爲了使這項工作,我只是從uri請求中刪除文件名,並將-OutFile xxxx.zip添加到Invoke-RestMethod cmdlet中。

相關問題