Exemple #1
0
        private void NavigationWithCookies()
        {
            Uri uri = new Uri(WcfApiUrlConstants.LoginUrl);
            //var httpBaseProtocolFilter = new HttpBaseProtocolFilter();
            //httpBaseProtocolFilter.UseProxy = true;
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
            var userAgent          = "Mozilla/5.0 (Windows Phone 10.0; Android 6.0.0; WebView/3.0; Microsoft; Virtual) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10240 sample/1.0";

            httpRequestMessage.Headers.Add("User-Agent", userAgent);
            if (_loginViewModel.IsLogin && _loginViewModel.Cookies != null)
            {
                //如果用于已经登陆,则请求带上当前用户的Cookies
                foreach (Cookie c in _loginViewModel.Cookies)
                {
                    HttpCookiePairHeaderValue httpCookie = new HttpCookiePairHeaderValue(c.Name, c.Value);
                    httpRequestMessage.Headers.Cookie.Add(httpCookie);
                }
            }
            LoginWebView.NavigateWithHttpRequestMessage(httpRequestMessage);
        }