C httpwebrequest Access HTTPS Error Handling Method
- 2021-11-30 01:15:45
- OfStack
C # httpwebrequest encountered this error while accessing the HTTPS link, but if I open a packet grabbing tool, such as filddler2, POST returns to normal
The Message of the error prompt is:
The underlying connection is closed: An error occurred while sending.
InnerException is:
An unexpected EOF or 0 bytes was received from the transport stream.
I tried N methods on the Internet, and the following is the solution this time:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
List the solutions found online under 1, and you may be able to solve your problem
Here are the solutions found online:
1. request.ProtocolVersion = HttpVersion.Version10;
2. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
3.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
4. Try changing to UserAgent
5. Add the following to App. config:
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>