获取EOF例外通过https电话 [英] Getting EOF exception over https call

查看:335
本文介绍了获取EOF例外通过https电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code使HTTPS请求。这是我的code

  HttpWebRequest的要求=(HttpWebRequest的)WebRequest.Create(的uploadURL);
            request.Method =POST;
            request.KeepAlive = FALSE;
            request.Credentials =新的NetworkCredential(用户ID,testpwd);

            POSTDATA =<根>< /根>中;
            request.ContentType =应用/的X WWW的形式urlen codeD;

            byte []的postDataBytes = Encoding.UTF8.GetBytes(POSTDATA);
            request.ContentLength = postDataBytes.Length;

            流requestStream = request.GetRequestStream();
            requestStream.Write(postDataBytes,0,postDataBytes.Length);
            requestStream.Close();

            使用(HttpWebResponse响应=(HttpWebResponse)request.GetResponse())
            {
                StreamReader的responseReader =新的StreamReader(response.GetResponseStream(),Encoding.UTF8);
                VAR的结果= responseReader.ReadToEnd();
                responseReader.Close();
                Console.WriteLine(结果);
            }
 

这code的运行良好,但以下情况例外突然投掷

  System.Net.WebException
 

     

异常消息是:   基础连接已关闭:上一个发送发生意外的错误

堆栈跟踪:    在System.Net.HttpWebRequest.GetRequestStream(TransportContext&安培;上下文)    在System.Net.HttpWebRequest.GetRequestStream()    在CustomerProcessor.Delivery.Deliver(字符串内容的Int32产品分类,标识字符串,字符串xsltFile)

该异常有一个内部异常: 发生异常: System.IO.IOException 异常消息为: 接收从传输流意想不到的EOF或0字节。

堆栈跟踪:    在System.Net.FixedSizeReader.ReadPacket(字节[]缓冲区的Int32偏移的Int32计数)    在System.Net.Security.SslState.StartReadFrame(字节[]缓冲区的Int32的ReadBytes,AsyncProtocolRequest的AsyncRequest)    在System.Net.Security.SslState.StartReceiveBlob(字节[]缓冲区,AsyncProtocolRequest的AsyncRequest)    在System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken消息,AsyncProtocolRequest的AsyncRequest)    在System.Net.Security.SslState.StartSendBlob(字节[]来电,的Int32算,As​​yncProtocolRequest的AsyncRequest)    在System.Net.Security.SslState.ForceAuthentication(布尔receiveFirst,字节[]缓冲区,AsyncProtocolRequest的AsyncRequest)    在System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)    在System.Net.TlsStream.CallProcessAuthentication(对象状态)    在System.Threading.ExecutionContext.runTry code(对象USERDATA)    在System.Runtime.CompilerServices.RuntimeHelpers.Execute codeWithGuaranteedCleanup(试行code code,清理code撤销code,对象USERDATA)    在System.Threading.ExecutionContext.RunInternal(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态)    在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态)    在System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult结果)    在System.Net.TlsStream.Write(字节[]缓冲区的Int32偏移的Int32大小)    在System.Net.PooledStream.Write(字节[]缓冲区的Int32偏移的Int32大小)    在System.Net.ConnectStream.WriteHeaders(布尔异步)

有没有机会看到这可能是这个问题的原因是什么?

解决方案

添加此调用之前请求帮助我:

  ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
 

所以,如果你使用的是HTTPS试图更改默认SecurityProtocol。

My code making https request. This is my code

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(UploadUrl);
            request.Method = "POST";
            request.KeepAlive = false;
            request.Credentials = new NetworkCredential(userid, testpwd);

            postData = "<root></root>";
            request.ContentType = "application/x-www-form-urlencoded";

            byte[] postDataBytes = Encoding.UTF8.GetBytes(postData);
            request.ContentLength = postDataBytes.Length;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(postDataBytes, 0, postDataBytes.Length);
            requestStream.Close();

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                var result = responseReader.ReadToEnd();
                responseReader.Close();
                Console.WriteLine(result);
            }

This code was running good but all of a sudden throwing following exception

System.Net.WebException

The exception message is: The underlying connection was closed: An unexpected error occurred on a send.

Stack Trace: at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at CustomerProcessor.Delivery.Deliver(String content, Int32 productCategory, String identifier, String xsltFile)

The Exception has an inner exception: An Exception occurred: System.IO.IOException The exception message is: Received an unexpected EOF or 0 bytes from the transport stream.

Stack Trace: at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 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.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 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)

Is there any chance to see what could be the cause of this issue?

解决方案

Adding this call before request helped me:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

So if you are using https try to change the default SecurityProtocol.

这篇关于获取EOF例外通过https电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆