Webclient下载意外异常

时间:2019-05-15 10:01:16

标签: c# .net webclient-download

我使用System.Net.WebClient下载pdf文件。对于某些文件,我遇到了一些麻烦,如下所述。现在,我可以在应用程序中针对特殊的URL重现该问题。其他网址可以正常工作,很好。我无法在应用程序外部重现该问题,例如在LinqPad中。

var url = @"https://content.fischer.de/cbfiles/upat/zulassungen/eta/zd_etab_u_10-0170_%23sde_%23aip_%23v3.pdf";
var fn = @"d:\2.tmp"; // writeable path !!!
using (var wc = new System.Net.WebClient())
{
    wc.DownloadFile(url, fn);
}

在我的演示应用程序(LinqPad)中,此代码可以正常工作。

在同一台计算机上完整的WinForm应用程序中,我收到一个

{System.Net.WebException}
{"The underlying connection was closed: An unexpected error occurred on a send."}   

InnerException

{System.IO.IOException}
{"Unable to read data from the transport connection: Eine vorhandene Verbindung wurde vom Remotehost geschlossen."}

用于内部异常的Stacktrace

at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.TlsStream.CallProcessAuthentication(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
   at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.ConnectStream.WriteHeaders(Boolean async)

我不知道造成这个问题的原因。

0 个答案:

没有答案