gpt4 book ai didi

vb.net - 在 GetReponse() 上获取 "The underlying connection was closed: An unexpected error occurred on a send"但不是通过浏览器获取

转载 作者:行者123 更新时间:2023-12-02 04:40:16 25 4
gpt4 key购买 nike

我正在尝试利用使用 GET 方法的 REST 服务。我正在使用.Net Framework 4.5.2。我下面写的只是一个测试,看看我是否真的可以提出请求。如果我将 URL 直接输入浏览器,我会得到良好的响应,其中包含 json 格式的字符串数据。但是当我尝试运行代码时,我最终收到以下错误:

“底层连接已关闭:发送时发生意外错误。”InnerException = {“无法从传输连接读取数据:现有连接被远程主机强制关闭。”}

我尝试将 keepalive 设置为 true 和 false,并且我也尝试使用 WebClient 和 DownloadString ....所有结果都会导致相同的错误。有人知道我缺少什么吗?或者这是服务器端的一个问题?

Dim script As String = "236"
Dim deploy As String = "1"
Dim compid As String = "915960_SB2"
Dim h As String = "value1"
Dim id As String = "1241389"
Dim status As String = "in freezer"
Dim request As HttpWebRequest
Dim response As HttpWebResponse

Try

'I have removed the real website name from this code.
Dim theurl As String = "https://website/app/site/hosting/scriptlet.nl?script={0}&deploy={1}&compid={2}&h={3}&Id={4}&Status={5}"
Dim url As String = String.Format(theurl, script, deploy, compid, h, id, status)

request = HttpWebRequest.Create(url)
request.Method = "GET"
request.ContentType = "application/json"

'This is where the error occurs
response = request.GetResponse()

Catch ex As Exception
Dim test as string=""
Finally

End Try

最佳答案

我解决了。我偶然发现以下网站,其他人也遇到了同样的问题。

http://www.avivroth.com/2013/05/02/rest-calls-in-net-c-over-ssl-https/

解决办法是设置安全协议(protocol)。我只是沿着列表从 ssl 到 tls11,然后到 tls12,发现最后一个有效。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

关于vb.net - 在 GetReponse() 上获取 "The underlying connection was closed: An unexpected error occurred on a send"但不是通过浏览器获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37218430/

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