Я получаю это исключение, когда пытаюсь загрузить строку с помощью WebClient.Я пытался во многих случаях настроить ServicePointManager:
ServicePointManager.Expect100Continue: true and false
ServicePointManager.SecurityProtocol: SecurityProtocolType.Ssl3
и
SecurityProtocolType.Tls12
и
(SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12)
и все Tls и все протоколы.Каждая комбинация была использована.Не работает.
Но если я использую команду curl - я хорошо получаю json.
curl -X GET https://myurl/2019-05-29
То же поведение в браузере
Система: Windows Server 2012 R2
.NET: Framework 4.6.1
Callstack :
Failed to get fixtures from URI=https://myurl/2019-05-29. System.Net.WebException:
An exception occurred during a WebClient request. --->System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.WebClient.DownloadBitsState.RetrieveBytes(Int32& bytesRetrieved)
at System.Net.WebClient.DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp)
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
--- End of inner exception stack trace ---
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at System.Net.WebClient.DownloadString(String address)
Код с одним регистром:
ServicePointManager.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12 |
SecurityProtocolType.Ssl3;
using (var wc = new WebClient())
{
try
{
var json = wc.DownloadString(uri);
return json;
}
catch (Exception e)
{
return null;
}
}