VB Webclient“基础连接已关闭”

问题描述

当我尝试从网站下载DownloadString时,我得到this error。该错误从未出现并且一直在起作用,我至少一个月以来都没有更改此代码行,但由于某种原因,它正在创建错误

只是一些有用的信息:变量“ Word”是每个用户输入的内容,我确保输入一个存在的单词,例如“ taberu”(日语单词),然后将其连接为“ https” ://jisho.org/search/taberu”,这应该可行,因为the page exists。 (我还检查了“汽车”窗口,对于串联肯定是正确的。

为什么会这样?我该如何解决

编辑;简而言之,这是我的代码

Dim Word As String = Console.Readline
Dim WordURL As String = "https://jisho.org/search/" & Word
Dim Client As New WebClient
Client.Encoding = System.Text.Encoding.UTF8

Dim HTML As String
HTML = Client.DownloadString(New Uri(WordURL)) 'this is the line that causes the error

解决方法

大约,添加以下代码行使其起作用

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

Tls11也可以

我不知道为什么,但是它解决了我的问题。 Source