示例#1
0
        public async Task <bool> SwitchConnectionTypeAsync(string connectionType)
        {
            await this.LoadHomePageWithCsrfAsync();

            var verboseType = ConnectionSwitchType.Parse(connectionType);

            Console.WriteLine("Switching to {0}", verboseType);

            var data =
                string.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><NetworkMode>{0}</NetworkMode><NetworkBand>3FFFFFFF</NetworkBand><LTEBand>7FFFFFFFFFFFFFFF</LTEBand></request>", connectionType);

            var request = new HttpRequestMessage()
            {
                RequestUri = new Uri(this.networkChangeUrl),
                Method     = HttpMethod.Post,
                Content    = new StringContent(data)
            };

            request.Headers.Add("__RequestVerificationToken", firstCsrf);

            var response = await this.client.SendAsync(request);

            var result = await response.Content.ReadAsStringAsync();

            if (result.Contains("OK"))
            {
                Console.WriteLine("Switching to {0}... OK!", verboseType);
                return(true);
            }

            Console.WriteLine("Switching to {0}... Failed!", verboseType);
            Console.WriteLine("Response was: {0}", result);

            return(false);
        }
示例#2
0
        /// <summary>
        /// Switches to LTE or 3G
        /// </summary>
        /// <param name="connectionType">Numeric value of the dropdown field in the Web UI</param>
        /// <returns>true if OK was found in response</returns>
        public bool SwitchConnectionType(string connectionType)
        {
            LoadHomePageWithCsrf();

            string verboseType = ConnectionSwitchType.Parse(connectionType);

            _logger.Info("Switching to {0}", verboseType);
            var dataToSend =
                string.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><NetworkMode>{0}</NetworkMode><NetworkBand>3FFFFFFF</NetworkBand><LTEBand>7FFFFFFFFFFFFFFF</LTEBand></request>", connectionType);
            var result = _website.PostPage(_networkChangeUrl, new PostData(dataToSend).AddHeader("__RequestVerificationToken", _firstCsrf));

            if (result.Contains("OK"))
            {
                _logger.Info("Switching to {0}... OK!", verboseType);
                return(true);
            }

            _logger.Error("Switching to {0}... Failed!", verboseType);
            _logger.Error("Response was: {0}", result);

            return(false);
        }