c# Why does System.net.WebException happen

Linlin Bian 20 Reputation points
2023-05-31T06:44:57.57+00:00

Preconditions:

The code is as follows:

ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;

using (WebClient client = new WebClient())

{

。。。。。。

IWebProxy proxy = Proxy.GetWebProxy(new Uri(address));

。。。。。。

byte[] resBytes = client.UploadValues(address, param);

}

abnormal:

The following fault occurs, but it does not occur every time it runs, it only occasionally occurs:

System.Net.WebException:

Connection disconnected: the connection that was needed to be cut was disconnected by the server.

  • system. Io.ioexception: unable to read data from a transfer connection: unable to connect because the connected caller did not respond correctly even after a certain period of time. The established connection failed because the connected host did not respond.

  • system. Net. Sockets. Socketexception: unable to connect because the connected caller did not respond correctly even after a certain period of time. The established connection failed because the connected host did not respond.

question:

What is the cause of the malfunction

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Linlin Bian 20 Reputation points
    2023-06-07T05:58:42.0333333+00:00

    Can no one answer this question?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.