From b8aa45a22b13e9d4220459c870c842546145c889 Mon Sep 17 00:00:00 2001 From: DanilKurkin Date: Mon, 7 Sep 2015 09:31:17 +0100 Subject: [PATCH] Aborting web request Without aborting connection android keeps the connection open. After requesting connection for third time - there were no response from server. Aborting request in when cancelToken=true fixes the problem. Tests were done using Xamarin.Forms + Xamarin Android --- EventSource4Net/ConnectedState.cs | 2 ++ EventSource4Net/WebRequester.cs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/EventSource4Net/ConnectedState.cs b/EventSource4Net/ConnectedState.cs index 7669993..2baa096 100644 --- a/EventSource4Net/ConnectedState.cs +++ b/EventSource4Net/ConnectedState.cs @@ -130,6 +130,8 @@ public Task Run(Action msgReceived, Cancellat //stream.Close(); //mResponse.Close(); //mResponse.Dispose(); + + WebRequester._WebRequest.Abort(); return new DisconnectedState(mResponse.ResponseUri, mWebRequesterFactory); } } diff --git a/EventSource4Net/WebRequester.cs b/EventSource4Net/WebRequester.cs index 092ca1d..f712276 100644 --- a/EventSource4Net/WebRequester.cs +++ b/EventSource4Net/WebRequester.cs @@ -9,9 +9,13 @@ namespace EventSource4Net { class WebRequester : IWebRequester { + public static WebRequest _WebRequest { get; set; } + private HttpWebRequest wreq { get; set; } + public Task Get(Uri url) { - var wreq = (HttpWebRequest)WebRequest.Create(url); + _WebRequest = WebRequest.Create(url); + wreq = (HttpWebRequest)_WebRequest; wreq.Method = "GET"; wreq.Proxy = null;