public async Task ClearCookiesAsync(LoginOptions options) { if (Window.Current == null) { return; } var frame = Window.Current.Content as Frame; if (frame != null) { await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var loginUri = new Uri(OAuth2.ComputeAuthorizationUrl(options)); var myFilter = new HttpBaseProtocolFilter(); HttpCookieManager cookieManager = myFilter.CookieManager; try { LoggingService.Log("attempting to clear cookies", LoggingLevel.Verbose); HttpCookieCollection cookies = cookieManager.GetCookies(loginUri); foreach (HttpCookie cookie in cookies) { cookieManager.DeleteCookie(cookie); } LoggingService.Log("clear cookies done", LoggingLevel.Verbose); } catch (ArgumentException ex) { LoggingService.Log("Exception occurred when clearing cookies", LoggingLevel.Critical); LoggingService.Log(ex, LoggingLevel.Critical); } }); } }
private async void ButtonWindowsWebHttp_OnClick(object sender, RoutedEventArgs e) { var httpBaseProtocolFilter = new HttpBaseProtocolFilter { AllowUI = true, CacheControl = { ReadBehavior = HttpCacheReadBehavior.NoCache, WriteBehavior = HttpCacheWriteBehavior.NoCache } }; HttpCookieManager cookieManager = httpBaseProtocolFilter.CookieManager; List <HttpCookie> cookies = cookieManager.GetCookies(_uri).ToList(); using (var httpClient = new HttpClient(httpBaseProtocolFilter)) { var requestMessage = new HttpRequestMessage(HttpMethod.Get, _uri); Request.Text = new StringBuilder().AppendLine(requestMessage.ToString()) .AppendLine(requestMessage.Headers.ToString()) .AppendLine(string.Join("\n", cookies)).ToString(); HttpResponseMessage responseMessage = await httpClient.SendRequestAsync(requestMessage); Request1.Text = new StringBuilder().AppendLine(responseMessage.RequestMessage.ToString()) .AppendLine(string.Join(" - ", cookies)).ToString(); Response.Text = responseMessage.ToString(); } }
public static async void ClearCookies(LoginOptions loginOptions) { var frame = Window.Current.Content as Frame; if (frame != null) { await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var loginUri = new Uri(ComputeAuthorizationUrl(loginOptions)); var myFilter = new HttpBaseProtocolFilter(); HttpCookieManager cookieManager = myFilter.CookieManager; try { PlatformAdapter.SendToCustomLogger("OAuth.ClearCookies - attempting at clearing cookies", LoggingLevel.Verbose); HttpCookieCollection cookies = cookieManager.GetCookies(loginUri); foreach (HttpCookie cookie in cookies) { cookieManager.DeleteCookie(cookie); } PlatformAdapter.SendToCustomLogger("OAuth2.ClearCookies - done", LoggingLevel.Verbose); } catch (ArgumentException ex) { PlatformAdapter.SendToCustomLogger("OAuth2.ClearCookies - Exception occurred when clearing cookies:", LoggingLevel.Critical); PlatformAdapter.SendToCustomLogger(ex, LoggingLevel.Critical); Debug.WriteLine("Error clearing cookies"); } }); } }
public ShopeeOrderPageViewModel() { ShopeeOrderPageLoading = new DelegateCommand(() => { StaticResources.SelectedShopLogin.NewOrderCount = 0; StaticResources.OrderFeature.SelfCount = 0; var bc = Utility.GetToProcessingBillCount(StaticResources.SelectedShopLogin); }); BtCancelGrPrinterTapped = new DelegateCommand(() => { this.TgGrPrinter = "Collapsed"; }); BtOpenPrinterTapped = new DelegateCommand(() => { this.TgGrPrinter = "Visible"; }); wvLoaded = new DelegateCommand <WebView>((s) => { if (s != null) { Uri sale_uri = new Uri(StaticResources.SaleUri); HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); Utility.ClearCookie(filter, sale_uri); HttpCookieManager cookieManager = filter.CookieManager; try { foreach (var ck in StaticResources.SelectedShopLogin.lstLoginCookie) { HttpCookie cookie = new HttpCookie(ck.name, ck.domain[0].Equals('.') ? ck.domain : "." + ck.domain, ck.path); cookie.Value = ck.value; cookieManager.SetCookie(cookie, false); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } new Thread(async() => { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { s.Navigate(sale_uri); }); }).Start(); } }); wvScriptNotify = new DelegateCommand <NotifyEventArgs>((s) => { }); }
/// <summary> /// Gets the title out of the HTML head section. /// </summary> /// <param name="url">The URL of the page</param> /// <param name="defaultIfNoMatch">string to return, if no match was found</param> /// <param name="credentials">Credentials for authenticating the request</param> /// <param name="proxy">Proxy server to direct the request through</param> /// <returns></returns> //dup to FindTitle2() - which one we should use? public static string FindTitle(string url, string defaultIfNoMatch, IWebProxy proxy, ICredentials credentials) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AllowAutoRedirect = true; request.Proxy = proxy; request.Credentials = credentials; request.Timeout = 5 * 1000 /* 5 second timeout */; if (FeedSource.SetCookies) { HttpCookieManager.SetCookies(request); } /* use bogus user agent since some sites will bounce you to unsupported browser page otherwise */ request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;)"; string title = defaultIfNoMatch; Stream stream = null; try { stream = request.GetResponse().GetResponseStream(); SgmlReader reader = new SgmlReader(); reader.InputStream = new StreamReader(stream); while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element) && (reader.Name.ToLower().Equals("title"))) { title = reader.ReadElementContentAsString(); stream.Flush(); break; } } //while } catch (Exception e) { _log.Debug("Error retrieving title from HTML page at " + url, e); } finally { if (stream != null) { stream.Close(); } } return(title); }
protected override void OnNavigatedTo(NavigationEventArgs e) { scopes = e.Parameter as List <TwitchConstants.Scope>; Uri authPageUri = AppConstants.Twixel.Login(scopes); HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); HttpCookieManager cookieManager = filter.CookieManager; HttpCookieCollection cookies = cookieManager.GetCookies(authPageUri); foreach (HttpCookie cookie in cookies) { cookieManager.DeleteCookie(cookie); } webView.Navigate(authPageUri); base.OnNavigatedTo(e); }
public ProperHttpClient() { var filter = new HttpBaseProtocolFilter(); // Nodrošina, ka HTTP client katru reizi veiks GET pieprasījumu (kuri atšķiras ar galvenēm, bet ne ar adresi). filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache; // Atļauj Bites pašparakstīto sertifikātu, kurš izdots uz "test.testas" domēnu. filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName); // Gadījumā, ja kādreiz serveris sadomās prasīt paroli, neļauj to attēlot grafiskā saskarnē. filter.AllowUI = false; // Manuāli apstrādā Mans LMT pāradresāciju, lai mazinātu trafiku. filter.AllowAutoRedirect = false; Client = new HttpClient(filter); CookieManager = filter.CookieManager; }
private void ClearCookie() { if (Uri.TryCreate(AuthorizeUrl, UriKind.Absolute, out var authUri)) { // capture the domain of the OAuth URL, then clear all cookies string targetUrl = $"{authUri.Scheme}://{authUri.Host}"; HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); HttpCookieManager manager = filter.CookieManager; HttpCookieCollection collection = manager.GetCookies(new Uri(targetUrl)); foreach (var item in collection) { manager.DeleteCookie(item); } } }
public API() { HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); filter.AutomaticDecompression = true; HttpClient http = new HttpClient(filter); cookieMonster = filter.CookieManager; client = http; loggedIn = false; gotInternet = false; //debug = true; network = new NetworkChanged(); Windows.Networking.Connectivity.NetworkInformation.NetworkStatusChanged += NetworkStatusChanged; }
public ShopeeChatPageViewModel() { ShopeeChatPageLoading = new DelegateCommand(() => { StaticResources.SelectedShopLogin.NewMessageCount = 0; StaticResources.MessageFeature.SelfCount = 0; }); wvLoaded = new DelegateCommand <WebView>((s) => { if (s != null) { Uri chat_uri = new Uri(StaticResources.ChatUri); HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); Utility.ClearCookie(filter, chat_uri); HttpCookieManager cookieManager = filter.CookieManager; try { foreach (var ck in StaticResources.SelectedShopLogin.lstLoginCookie) { HttpCookie cookie = new HttpCookie(ck.name, ck.domain[0].Equals('.') ? ck.domain : "." + ck.domain, ck.path); cookie.Value = ck.value; cookieManager.SetCookie(cookie, false); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } new Thread(async() => { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { s.Navigate(chat_uri); }); }).Start(); } }); }
public string GetCookiesForUrl(Uri address) { Program._lastUpdated = DateTime.Now; return(HttpCookieManager.RetrieveIECookiesForUrl(address.AbsoluteUri)); }
//dup to FindTitle() - which one we should use? public static string FindTitle2(string url, string defaultIfNoMatch, IWebProxy proxy, ICredentials credentials) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AllowAutoRedirect = true; request.Proxy = proxy; request.Credentials = credentials; request.Timeout = 5 * 1000 /* 5 second timeout */; if (FeedSource.SetCookies) { HttpCookieManager.SetCookies(request); } /* use bogus user agent since some sites will bounce you to unsupported browser page otherwise */ request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;)"; string title = defaultIfNoMatch; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (FastSgmlXPathReader sgmlReader = new FastSgmlXPathReader()) { using (StreamReader inputStreamReader = new StreamReader(response.GetResponseStream())) { try { sgmlReader.InputStream = inputStreamReader; sgmlReader.DocType = "HTML"; sgmlReader.CaseFolding = CaseFolding.ToLower; bool done = false; while (!done && sgmlReader.Read()) { if (sgmlReader.NodeType == XmlNodeType.Element) { switch (sgmlReader.XPath) { case "//html/title": title = sgmlReader.ReadElementContentAsString(); // .ReadInnerXml(); done = true; break; case "//html/head/title": title = sgmlReader.ReadElementContentAsString(); // .ReadInnerXml(); done = true; break; case "//html/body": done = true; break; } } } //while } catch (Exception e) { _log.Debug("Error retrieving title from HTML page at " + url, e); } } } } return(title); }