获取响应流时出错(ReadDone1):ReceiveFailure

时间:2015-02-09 19:55:39

标签: c# android xamarin webrequest

我正在使用Xamarin开发Android应用程序,在将Xamarin升级到它的最新版本后,我的WebRequest中抛出以下异常:

  

{System.Net.WebException:获取响应流时出错(ReadDone1):   ReceiveFailure ---> System.IO.IOException:EndRead失败--->   System.Net.Sockets.SocketException:由peer重置连接   System.Net.Sockets.Socket.EndReceive(IAsyncResult result)[0x00000]   in:0在System.Net.Sockets.NetworkStream.EndRead(IAsyncResult ar)   [0x00000] in:0   ---内部异常堆栈跟踪的结束---在System.Net.Sockets.NetworkStream.EndRead(IAsyncResult ar)[0x00000]   in:0 at   Mono.Security.Protocol.Tls.SslStreamBase.InternalReadCallback   (IAsyncResult结果)[0x00000] in:0   ---内部异常堆栈跟踪结束---在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)   [0x00000] in:0 at   System.Threading.Tasks.TaskFactory1 [System.Net.WebResponse] .InnerInvoke   (System.Threading.Tasks.TaskCompletionSource1 tcs,System.Func

     

2 endMethod,IAsyncResult l)[0x00000] in:0   ---从抛出异常的先前位置开始的堆栈跟踪结束--- at   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()   [0x00000] in:0 at   System.Runtime.CompilerServices.TaskAwaiter   1 [System.Net.WebResponse] .GetResult()[0x00000] in:0 at   Modulo.CICC.Chat.Core.ConnectionFactory.WebServices + d__32.MoveNext()   [0x000db]在c:\ Users \ Raphael中   阿尔瓦伦加\文件\项目\ SESGE \ Modulo.CICC.Chat \ Modulo.CICC.Chat.Core \连接工厂\ WebServices.cs:205   }

以下是代码:

try
{
    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);

    string data = "access_token=" + System.Web.HttpUtility.UrlEncode(accessToken) + "&refresh_token=" + System.Web.HttpUtility.UrlEncode(refreshToken);

    WebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(url + "?" + data);

    myWebRequest.Method = method;
    myWebRequest.ContentLength = data.Length;
    myWebRequest.ContentType = "application/x-www-form-urlencoded";
    HttpWebResponse response = await myWebRequest.GetResponseAsync() as HttpWebResponse;

    string headerSetCookie = response.Headers["Set-Cookie"];
    response.Close();
    return headerSetCookie;    
}
catch (Exception e)
{
    throw e;
}

有什么想法会抛出异常? 同样在Xamarin的论坛中发布了这个问题:https://forums.xamarin.com/discussion/32554/error-getting-response-stream-readdone1-receivefailure?new=1

谢谢。

0 个答案:

没有答案