gpt4 book ai didi

PowerShell 安装 NuGet,说无法访问互联网,但我实际上可以

转载 作者:行者123 更新时间:2023-12-02 11:26:06 25 4
gpt4 key购买 nike

我遵循了 Using PowerShell Behind a Proxy 中提到的步骤配置我的代理服务器。

netsh winhttp set proxy "[IP]:[Port]"
$Wcl = New-Object System.Net.WebClient
$Creds = Get-Credential
$Wcl.Proxy.Credentials = $Creds

弹出一个对话框以在第三行收集我的凭据。

然后我尝试安装 NuGet:
PS C:\Users\Administrator> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/
?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet
connection.
Install-PackageProvider : No match was found for the specified search criteria
for the provider 'NuGet'. The package provider requires 'PackageManagement' and
'Provider' tags. Please check if the specified package has the tags.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

错误消息似乎表明我的 PowerShell 无法连接到互联网,但是当我尝试使用此命令时:
PS C:\Users\Administrator> Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409"

StatusCode : 200
StatusDescription : OK
Content : <?xml version="1.0" encoding="utf-8"?>
<SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:discovery="http://p...
RawContent : HTTP/1.1 200 OK
Content-MD5: 01uMBNqAHedJsS1dqKC5oA==
Vary: Accept-Encoding
X-Cache: HIT
x-ms-blob-type: BlockBlob
x-ms-lease-status: unlocked
x-ms-request-id: 1b7af5a7-901e-0003-5d94-f5cc950000...
Forms : {}
Headers : {[Content-MD5, 01uMBNqAHedJsS1dqKC5oA==], [Vary, Accept-Encoding], [X-Cache, HIT],
[x-ms-blob-type, BlockBlob]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 1847

看来它毕竟可以连接到Internet。

我做错了什么?如何安装 NuGet?

编辑:
我尝试了 Ocaso Protal 的建议:
PS C:\Users\Administrator> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -proxy [ProxyServer:Port] -proxycredential $Creds
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package
provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
kageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
vider

PS C:\Users\Administrator> $Creds

UserName Password
-------- --------
[My UserName] System.Security.SecureString

好像没什么效果。

最佳答案

可能与 TLS 安全相关(引用:https://rnelson0.com/2018/05/17/powershell-in-a-post-tls1-1-world/)

先试试这个命令:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

然后尝试进行更新。
注意:该命令只影响当前 session ,不会持久化。

您还可以检查计算机上为客户端设置的 TLS 版本。看起来客户端需要 TLS 1.0。 (引用: https://powershell.org/forums/topic/wmf-5-1-upgrade-broken-repositories/ )

迈克尔

关于PowerShell 安装 NuGet,说无法访问互联网,但我实际上可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55826791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com