在尝试连接到Nuget时,我得到了下面的错误,然后我无法连接:

无法加载源的服务索引 https://api.nuget.org/v3/index.json。 发送请求时发生错误。 无法连接到远程服务器 连接尝试失败,原因是被连接方在一段时间后没有正确响应,或已建立连接 由于连接的主机未能响应68.232.34.200:443而失败

我可以在浏览器上访问https://api.nuget.org/v3/index.json。


当前回答

我在Windows 10中使用docker-compose up命令在Dockerfile中运行RUN dotnet restore时遇到了同样的错误。

我已经尝试了互联网上提供的所有可能的解决方案,也一直在关注这个公开的问题。最后,在花了8个多小时后,通过遵循前面的步骤,我能够解决我的问题。

Uninstall Docker from your system Restart your system Install Docker from this link. Below is the version of my Docker Restart your system Start Docker for Windows, search Docker in the search bar in Windows. Make sure it is running. You should also go to Services.msc and make sure the services Docker Engine and Docker for Windows Service are running. At last, you must check your Nuget.config file from C:\Users\{Username}\AppData\Roaming\NuGet. For me, the content of that file was as below. <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> </packageSources> <packageRestore> <add key="enabled" value="True" /> <add key="automatic" value="True" /> </packageRestore> <bindingRedirects> <add key="skip" value="False" /> </bindingRedirects> <packageManagement> <add key="format" value="0" /> <add key="disabled" value="False" /> </packageManagement> </configuration> Hope this helps.

其他回答

安装小提琴也给我带来了类似的问题。卸载fiddler并从机器中删除fiddler代理。config(来自Framework和Framework64)解决了这个问题。

新包管理器的开发人员在2019年建议禁用tls 1.3作为解决方案(见第7705期)。

通过按Win + R打开注册表编辑器,并键入regedit Enter

导航到:

\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client

将“DisabledByDefault key 0”的值修改为1

然后重新启动Visual Studio。

在维基百科上阅读更多关于TLS的信息 阅读更多关于问题7705 w.r.t. NuGet在github

第三方编辑

请注意,这将禁用操作系统的tls 1.3,而不仅仅是对nuget或dotnet。 Windows 10 1909版确实包含TLS 1.3的实验性实现,但后续版本应该没问题。基于无法浏览nuget包的一个答案,您可以通过控制台程序测试tls是否存在问题

static async Task Main(string[] args)
{
    var client = new HttpClient();
    string uri = "https://apiint.nugettest.org/v3-index/index.json";
    var response = await client.GetAsync(uri);
    string msg = "If you see this, your machine has no TLS/SSL issues with nuget.org";
    Console.WriteLine(msg);

}

那些说要删除Nuget的答案。如果您正在使用自定义提要,Config将不起作用。如果您正在使用自定义提要,则需要编辑Nuget。配置文件指向自定义提要的索引。

转到%appdata%\NuGet\NuGet.config 修改这一行: < packageSources > <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft sdk \NuGetPackages\" /> . <add key="Package source" value="https://api.nuget.org/v3/index.json" /> . < / packageSources >

你的一个金块来源可能无法到达。

在撰写本文时,AspNetCore (https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json)似乎有一个过期的证书或已被完全删除。

只需从设置中删除nuget源就可以解决这个问题