WebClient可以';t从localhost下载字符串
本文关键字:localhost 下载 字符串 可以 WebClient | 更新日期: 2023-09-27 18:30:08
我想使用WebClient.DownloadString方法从https://localhost:3000/
下载内容,但此调用最终以SocketException: No connection could be made because the target machine actively refused it
结束,尽管可以通过浏览器访问地址。
我发现,当我用127.0.0.1
替换时,该请求是成功的(所以地址是https://127.0.0.1:3000
)。
我如何修复它,以便使用localhost地址(由于SSL证书,它需要是localhost)?
WebClient正在将localhost
地址转换为IPv6地址::1
,我对此一无所知。所以我在主机文件::1 localhost
中添加了新行,并将服务器侦听地址更改为::1
。