[英]Trying to download a file from an Azure DevOps Git repo using Powershell
[英]Getting "(406) Not Acceptable" when trying to download a git repo using powershell
我正在尝试使用 powershell 将存储库下载为 zip 文件。 下面是我正在尝试的方法。
$token = "MyGitToken";
$repo = "https://github.com/my-private-repo/archive/master.zip";
$targetFile = "./master.zip";
$restRequest = @{
Method = "Get"
Uri = "$repo"
Headers = @{
Authorization = "Token $token"
Accept = "application/vnd.github.v3.raw"
}
};
$response = Invoke-RestMethod @restRequest -OutFile $targetFile;
我得到以下错误。 知道如何按照评论中的建议解决此问题..
System.Net.WebException: The remote server returned an error: (406) Not Acceptable.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
PS:当我在浏览器中直接点击 $repo url 时,我能够下载 zip 文件。
编辑:更新了Invoke-RestMethod
命令以仅使用OutFile
而不是管道它。
HTTP Accept header 是对服务器的指令说
嘿,我只能理解这些格式
所以,在你的要求中,你说
Github,我想要这个文件,但我也希望你帮我做一些工作,把它变成这种格式,kthanxbai
GitHub 响应 406 Unacceptable 因为它没有时间处理您或您奇怪的请求格式,并且还因为您在最后保留了*
选项,这意味着“我将采用任何格式”。
要修复,请尝试在没有接受 header 的情况下执行请求,或者像这样修改您的 header:
Accept = "application/vnd.github.v3.raw,*"
资源:
Accept header 告诉服务器浏览器正在寻找什么文件格式,或者更准确地说是 MIME 类型...
https://www.newmediacampaigns.com/blog/browser-rest-http-accept-headers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.