private async Task OnAddCookieRequested(System.Net.Cookie cookie) { if (Control == null || cookie == null || String.IsNullOrEmpty(cookie.Domain) || String.IsNullOrEmpty(cookie.Name)) { return; } var nsCookie = new NSHttpCookie(cookie); if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { var store = _configuration.WebsiteDataStore.HttpCookieStore; await store.SetCookieAsync(nsCookie); } NSHttpCookieStorage.SharedStorage.SetCookie(nsCookie); foreach (var cookies in NSHttpCookieStorage.SharedStorage.Cookies) { System.Diagnostics.Debug.WriteLine(cookie.ToString()); } if (!_cookieDomains.ContainsKey(cookie.Domain)) { _cookieDomains[cookie.Domain] = 0; } _cookieDomains[cookie.Domain] = _cookieDomains[cookie.Domain] + 1; #if DEBUG await OnPrintCookiesRequested(); #endif }
public T ProcessRequest(string token, string logOn, string password, System.Net.Cookie cookie) { Uri uri = ToUrl(token); System.Net.HttpWebRequest wr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); wr.Credentials = new System.Net.NetworkCredential(logOn, password); wr.CookieContainer = new System.Net.CookieContainer(); if (cookie != null) { var cookiUri = cookie.Domain != null ? new Uri(cookie.Domain) : BaseUrl; wr.CookieContainer.SetCookies(uri, cookie.ToString()); } OnProcessingRequest(wr); #if !PORTABLE using (var response = wr.GetResponse()) using (var stream = response.GetResponseStream()) #else using (var stream = wr.GetRequestStreamAsync().Result) #endif { if (stream == null) { throw new InvalidOperationException("Response stream is null"); } var sr = new System.IO.StreamReader(stream); var jsonResult = sr.ReadToEnd(); var result = JsonParser.ParseJsonResult(jsonResult); if (result != null && result.CacheId != 0) { _cacheId = result.CacheId; } var ret = new T { Result = result }; OnProcessedRequest(ret); return(ret); } }
private void SetCookie(System.Net.Cookie cookie) { var cookieDomain = cookie.Domain; var url = $"{cookieDomain}"; var cookieString = $"{cookie.ToString()}; Domain={cookieDomain}; Path={cookie.Path}"; //CookieSyncManager cookieSyncManager = CookieSyncManager.CreateInstance(_webView.Context); CookieManager cookieManager = CookieManager.Instance; CookieManager.Instance.SetAcceptCookie(true); CookieManager.Instance.RemoveAllCookie(); System.Threading.Thread.Sleep(500); CookieManager.Instance.SetCookie(url, cookieString); //cookieSyncManager.Sync(); if (!_cookieDomains.ContainsKey(cookie.Domain)) { _cookieDomains[cookie.Domain] = 0; } _cookieDomains[cookie.Domain] = _cookieDomains[cookie.Domain] + 1; }