Rap*_*nga 8 c# android webrequest xamarin
我正在使用Xamarin开发一个Android应用程序,在将Xamarin升级到它的最新版本之后,我的WebRequest中抛出了以下异常:
{System.Net.WebException:获取响应流时出错(ReadDone1):ReceiveFailure ---> System.IO.IOException:EndRead failure ---> System.Net.Sockets.SocketException:System.Net.Sockets上的peer重置连接.Socket.EndReceive(IAsyncResult结果)[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 result)[0x00000] in:0 ---内部异常堆栈跟踪结束---在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)[0x00000] in:0 in System.Threading.Tasks.TaskFactory1 [System.Net.WebResponse] .InnerInvoke(System.Threading.Tasks.TaskCompletionSource1 tcs,System.Func)
2 endMethod,IAsyncResult l)[0x00000] in:0 ---从抛出异常的上一个位置开始的堆栈跟踪结束---在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] in c:\ Users\Raphael Alvarenga\Documents\Projects\SESGE\Modulo.CICC.Chat\Modulo.CICC.Chat.Core\ConnectionFactory\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;
}
Run Code Online (Sandbox Code Playgroud)
有什么想法它会引发异常吗?还在Xamarin论坛上发布了这个问题:https://forums.xamarin.com/discussion/32554/error-getting-response-stream-readdone1-receivefailure?new = 1
谢谢你的问候.