Exemplo n.º 1
0
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     cts.Cancel();
     cts.Dispose();
     httpClient.Dispose();
     filter.Dispose();
 }
Exemplo n.º 2
0
        private async Task GetWebServiceRelatedDataAsync(ReDataGroup group)
        {
            try
            {
                if ((group == null) && (group.UniqueId.Equals(string.Empty)))
                {
                    return;
                }

                string requestUrl = "http://replatform.cloudapp.net:8000/getrelated/?id={0}&uuid={1}&type={2}&from={3}&to={4}";
                //string requestUrl = "http://192.168.1.215:9999/getrelated/?id={0}";
                requestUrl = String.Format(requestUrl, group.UniqueId, App.gDeviceName, App.gDeviceType, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo());

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient       = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior  = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);

                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }

                GetRelatedResultJsonData(group, jsonText);
            }
            catch (Exception e)
            {
                String ex = e.Message;
            }
        }
        public void Dispose()
        {
            httpClient?.Dispose();
            httpClient = null;

            cts?.Dispose();
            cts = null;

            filter?.Dispose();
            filter = null;
        }
        public void Dispose()
        {
            if (filter != null)
            {
                filter.Dispose();
                filter = null;
            }

            if (httpClient != null)
            {
                httpClient.Dispose();
                httpClient = null;
            }

            if (cts != null)
            {
                cts.Dispose();
                cts = null;
            }
        }
Exemplo n.º 5
0
        private async Task GetContentsWebServiceDataAsync(string uniqueId)
        {
            if (String.IsNullOrWhiteSpace(uniqueId))
            {
                return;
            }

            try
            {
                string requestUrl = "http://replatform.cloudapp.net:8000/getTopical/?id={0}&uuid={1}&type={2}&from={3}&to={4}&r={5}";
                Random random     = new Random();
                int    r          = random.Next();
                requestUrl = String.Format(requestUrl, uniqueId, App.gDeviceName, App.gDeviceType, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo(), r);

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient       = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior  = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);

                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                GetContentResultJsonData(jsonText);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }
            }
            catch (Exception) { }
        }
Exemplo n.º 6
0
        private async Task GetWebServiceDataAsync()
        {
            try
            {
                string requestUrl = "http://replatform.cloudapp.net:8000/getguess/?uuid={0}&type={1}&page={2}&from={3}&to={4}&r={5}";
                //string requestUrl = "http://192.168.1.215:9999/getguess/?uuid={0}&page={1}";
                string userid = App.gDeviceName;
                string type   = App.gDeviceType;
                Random random = new Random();
                int    page   = defaultPageValue;//random.Next(iMinInclusivePageValue, iMaxExclusivePageValue);
                int    r      = random.Next();
                requestUrl = String.Format(requestUrl, userid, type, page, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo(), r);

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient       = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior  = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);

                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                GetResultJsonData(jsonText);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }
            }
            catch (Exception) {}
        }
Exemplo n.º 7
0
        //private async Task GetReDataAsync()
        //{
        //    if (this._groups.Count != 0)
        //        return;

        //    Uri dataUri = new Uri("ms-appx:///DataModel/ReData.json");

        //    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
        //    string jsonText = await FileIO.ReadTextAsync(file);
        //    JsonObject jsonObject = JsonObject.Parse(jsonText);
        //    JsonArray jsonArray = jsonObject["Groups"].GetArray();

        //    foreach (JsonValue groupValue in jsonArray)
        //    {
        //        JsonObject groupObject = groupValue.GetObject();
        //        ReDataGroup group = new ReDataGroup(groupObject["UniqueId"].GetString(),
        //                                                    groupObject["Title"].GetString());
        //        int index = 0;
        //        foreach (JsonValue itemValue in groupObject["Items"].GetArray())
        //        {
        //            JsonObject itemObject = itemValue.GetObject();

        //            string uniqueIdTmp = itemObject["UniqueId"].GetString();
        //            string titleTmp = itemObject["Title"].GetString();
        //            string subTitleTmp = itemObject["Subtitle"].GetString();
        //            string imagePathTmp = itemObject["ImagePath"].GetString();
        //            string descriptionTmp = itemObject["Description"].GetString();
        //            string playUrlTmp = itemObject["PlayUrl"].GetString();
        //            ReDataItem ri = new ReDataItem(index, uniqueIdTmp);
        //            group.Items.Add(ri);
        //            index++;
        //        }
        //        this.Groups.Add(group);
        //    }
        //}

        private async Task GetWebServiceDataAsync()
        {
            if (this._groups.Count != 0)
            {
                return;
            }
            try
            {
                string requestUrl = "http://replatform.cloudapp.net:8000/getpopular/?uuid={0}&type={1}&from={2}&to={3}";
                requestUrl = String.Format(requestUrl, App.gDeviceName, App.gDeviceType, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo());

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient       = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior  = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);

                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                GetResultPopularJsonData(jsonText);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }
            }
            catch (Exception) {}
        }
Exemplo n.º 8
0
        private async Task PostWebServiceDataAsync(string mediaId)
        {
            try
            {
                Random random = new Random();
                int r = random.Next();
                string requestUrl = "http://replatform.cloudapp.net:8000/userAction?uuid={0}&type={1}&media_id={2}&from={3}&to={4}&r={5}";
                string userid = App.gDeviceName;
                requestUrl = String.Format(requestUrl, userid, App.gDeviceType, mediaId, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo(), r);

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);
                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                GetPostUserActionResult(jsonText);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }
            }
            catch (Exception) { }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            if (mFilter != null)
            {
                mFilter.Dispose();
                mFilter = null;
            }

            if (mHttpClient != null)
            {
                mHttpClient.Dispose();
                mHttpClient = null;
            }

            if (cts != null)
            {
                cts.Dispose();
                cts = null;
            }
        }
Exemplo n.º 10
0
        public async Task ShowWebView(int width, int height)
        {
            appWindow = await AppWindow.TryCreateAsync();

            webView.Width  = width;
            webView.Height = height;
            appWindow.RequestSize(new Windows.Foundation.Size(width, height));
            ElementCompositionPreview.SetAppWindowContent(appWindow, webView);

            httpRequestMessage.Method     = HttpMethod.Get;
            httpRequestMessage.RequestUri = new Uri(loginUri);
            appWindow.Closed += delegate
            {
                appWindow = null;
                httpRequestMessage.Dispose();
                filter.Dispose();
                webView.Stop();
            };
            webView.NavigateWithHttpRequestMessage(httpRequestMessage);
            await appWindow.TryShowAsync();
        }
Exemplo n.º 11
0
        private async Task GetWebServiceRelatedDataAsync(ReDataGroup group)
        {
            try
            {
                if ((group == null) && (group.UniqueId.Equals(string.Empty)))
                {
                    return;
                }

                string requestUrl = "http://replatform.cloudapp.net:8000/getrelated/?id={0}&uuid={1}&type={2}&from={3}&to={4}";
                //string requestUrl = "http://192.168.1.215:9999/getrelated/?id={0}";
                requestUrl = String.Format(requestUrl, group.UniqueId, App.gDeviceName, App.gDeviceType, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo());

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);
                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }

                GetRelatedResultJsonData(group, jsonText);                
            }
            catch (Exception e) 
            {
                String ex = e.Message;
            }
        }
Exemplo n.º 12
0
        public async void GetAccountBasicInfo(string username, string passowrd)
        {
            HttpClient             client   = null;
            HttpRequestMessage     request  = null;
            HttpResponseMessage    response = null;
            HttpBaseProtocolFilter filter   = new HttpBaseProtocolFilter();

            try
            {
                client = new HttpClient(filter);

                response = await client.GetAsync(new Uri("https://jfself.bjut.edu.cn/LoginAction.action"));

                string re = await response.Content.ReadAsStringAsync();

                int index = re.IndexOf("checkcode=\"");
                if (index <= 0)
                {
                    return;
                }
                string checkcode = "";
                while (re[index + "checkcode=\"".Length] != '\"')
                {
                    checkcode += re[index + "checkcode=\"".Length];
                    index++;
                }

                response = await client.GetAsync(new Uri("https://jfself.bjut.edu.cn/RandomCodeAction.action?randomNum=0.124"));

                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("account", username);
                parameters.Add("password", passowrd);
                parameters.Add("checkcode", checkcode);

                request         = new HttpRequestMessage(HttpMethod.Post, new Uri("https://jfself.bjut.edu.cn/LoginAction.action"));
                request.Content = new HttpFormUrlEncodedContent(parameters);
                request.Headers["ContentType"] = "application/x-www-form-urlencoded";
                await client.SendRequestAsync(request);

                request.Dispose();
                request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://jfself.bjut.edu.cn/refreshaccount?t=1"));
                request.Headers["XRequestedWith"] = "XMLHttpRequest";
                response = await client.SendRequestAsync(request);

                JsonObject json = JsonObject.Parse(await response.Content.ReadAsStringAsync());
                TotalThroughputDigit = Convert.ToDouble(json["note"].GetObject()["leftFlow"].GetString());
                Service     = json["note"].GetObject()["service"].GetString();
                CurrentUser = json["note"].GetObject()["welcome"].GetString();
            }
            catch
            {
                TotalThroughputDigit = 0;
                service     = "";
                CurrentUser = "";
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
                if (request != null)
                {
                    request.Dispose();
                }
                if (client != null)
                {
                    client.Dispose();
                }
                if (filter != null)
                {
                    filter.Dispose();
                }
            }
        }
Exemplo n.º 13
0
        //public static async Task<ReDataItem> GetItemAsync(string uniqueId)
        //{
        //    //await _reDataSource.GetReDataAsync();
        //    await _reSearchDataSource.GetWebServiceDataAsync();

        //    // Simple linear search is acceptable for small data sets
        //    var matches = _reSearchDataSource.Groups.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals(uniqueId));
        //    if (matches.Count() == 1) return matches.First();
        //    return null;
        //}

        //private async Task GetReDataAsync()
        //{
        //    if (this._groups.Count != 0)
        //        return;

        //    Uri dataUri = new Uri("ms-appx:///DataModel/ReData.json");

        //    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
        //    string jsonText = await FileIO.ReadTextAsync(file);
        //    JsonObject jsonObject = JsonObject.Parse(jsonText);
        //    JsonArray jsonArray = jsonObject["Groups"].GetArray();
            
        //    foreach (JsonValue groupValue in jsonArray)
        //    {
        //        JsonObject groupObject = groupValue.GetObject();
        //        ReDataGroup group = new ReDataGroup(groupObject["UniqueId"].GetString(),
        //                                                    groupObject["Title"].GetString());
        //        int index = 0;
        //        foreach (JsonValue itemValue in groupObject["Items"].GetArray())
        //        {                    
        //            JsonObject itemObject = itemValue.GetObject();

        //            string uniqueIdTmp = itemObject["UniqueId"].GetString();
        //            string titleTmp = itemObject["Title"].GetString();
        //            string subTitleTmp = itemObject["Subtitle"].GetString();
        //            string imagePathTmp = itemObject["ImagePath"].GetString();
        //            string descriptionTmp = itemObject["Description"].GetString();
        //            string playUrlTmp = itemObject["PlayUrl"].GetString();
        //            ReDataItem ri = new ReDataItem(index, uniqueIdTmp);
        //            group.Items.Add(ri);
        //            index++;
        //        }
        //        this.Groups.Add(group);
        //    }
        //}

        private async Task GetWebServiceSearchDataAsync(string key)
        {
            try
            {
                key = System.Net.WebUtility.UrlEncode(key);
                string requstUrl = "http://replatform.cloudapp.net:8000/getsearch?v={0}&uuid={1}&type={2}&from={3}&to={4}";
                requstUrl = String.Format(requstUrl, key, App.gDeviceName, App.gDeviceType, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo());

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requstUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);
                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                GetSearchResultJsonData(jsonText);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }
            }
            catch(Exception) {}
        }
Exemplo n.º 14
0
        public async Task Authenticate()
        {
            var selWifi = cbNetList.SelectedItem as Windows.Devices.WiFi.WiFiAvailableNetwork;

            if (selWifi == null)
            {
                await new MessageDialog("选择的wifi型号参数不正确").ShowAsync();
                return;
            }
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            switch (selWifi.Ssid)
            {
            case "bjut_wifi":
            {
                parameters.Clear();
                parameters.Add("0MKKey", "123");
                parameters.Add("DDDDD", user.UserInfo.UserName);
                parameters.Add("upass", user.UserInfo.Password);

                HttpClient                httpClient = null;
                HttpRequestMessage        request    = null;
                HttpFormUrlEncodedContent postData   = null;
                HttpResponseMessage       response   = null;
                try
                {
                    httpClient = new HttpClient();
                    response   = await httpClient.GetAsync(new Uri("http://wlgn.bjut.edu.cn/"));

                    string responseString = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.Ok)
                    {
                        if (responseString.Contains("url4"))
                        {
                            await new MessageDialog("已经认证成功").ShowAsync();
                            Frame.Navigate(typeof(MainPage));
                            Frame.Navigate(typeof(Login));
                        }
                        else
                        {
                            string posturi = "http://wlgn.bjut.edu.cn/";
                            request         = new HttpRequestMessage(HttpMethod.Post, new Uri(posturi));
                            postData        = new HttpFormUrlEncodedContent(parameters);
                            request.Content = postData;
                            response        = await httpClient.SendRequestAsync(request);

                            responseString = await response.Content.ReadAsStringAsync();

                            if (response.StatusCode == HttpStatusCode.Ok)
                            {
                                #region 针对其他认证方式的结果判断逻辑
                                if (responseString.Contains("url4") || responseString.Contains("注销"))
                                {
                                    await new MessageDialog("认证成功").ShowAsync();
                                    Frame.Navigate(typeof(MainPage));
                                    Frame.Navigate(typeof(Login));
                                }
                                else
                                {
                                    int    statusCode;
                                    string flagString = "Msg=";
                                    string status     = string.Empty;
                                    int    index      = responseString.IndexOf(flagString);
                                    for (int i = index + flagString.Length + 1; i < 10; i++)
                                    {
                                        var t = responseString[i];
                                        if (t != ';')
                                        {
                                            status += t;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    statusCode = int.Parse(status);
                                    if (statusCode == 1)
                                    {
                                        await new MessageDialog("账号或密码不对,请重新输入").ShowAsync();
                                    }
                                    else if (statusCode == 2)
                                    {
                                        await new MessageDialog("该账号正在使用中,请您与网管联系").ShowAsync();
                                    }
                                    else if (statusCode == 3)
                                    {
                                        await new MessageDialog("用户名无效,可能已从本系统注销").ShowAsync();
                                    }
                                    else if (statusCode == 4)
                                    {
                                        await new MessageDialog("本账号费用超支或时长流量超过限制").ShowAsync();
                                    }
                                    else if (statusCode == 5)
                                    {
                                        await new MessageDialog("本账号暂停使用").ShowAsync();
                                    }
                                    else if (statusCode == 15)
                                    {
                                        await new MessageDialog("登录成功").ShowAsync();
                                    }
                                }
                                #endregion
                            }
                            else
                            {
                                await new MessageDialog(response.StatusCode.ToString()).ShowAsync();
                            }
                        }
                    }
                    else
                    {
                        await new MessageDialog("网络异常").ShowAsync();
                    }
                }
                catch (Exception ex)
                {
                    await new MessageDialog(ex.Message).ShowAsync();
                }
                finally
                {
                    if (httpClient != null)
                    {
                        httpClient.Dispose();
                    }
                    if (request != null)
                    {
                        request.Dispose();
                    }
                    ;
                    if (postData != null)
                    {
                        postData.Dispose();
                    }
                    if (response != null)
                    {
                        response.Dispose();
                    }
                }
            }
            break;

            case "Tushuguan":
            {
                HttpStringContent httpStringContent = new HttpStringContent(
                    "PtUser="******"&PtPwd=" + user.UserInfo.Password
                    + "&PtButton=%B5%C7%C2%BC");
                HttpBaseProtocolFilter    filter     = null;
                HttpClient                httpClient = null;
                HttpRequestMessage        request    = null;
                HttpFormUrlEncodedContent postData   = null;
                HttpResponseMessage       response   = null;
                try
                {
                    httpClient = new HttpClient();

                    string posturi = "http://172.24.39.253/portal/logon.cgi";
                    request = new HttpRequestMessage(HttpMethod.Post, new Uri(posturi));

                    request.Content = httpStringContent;
                    response        = await httpClient.SendRequestAsync(request);

                    string responseString = await response.Content.ReadAsStringAsync();

                    //获取cookie
                    filter = new HttpBaseProtocolFilter();

                    HttpCookieCollection cookieCollection = filter.CookieManager.GetCookies(new Uri(posturi));

                    //设置cookie
                    foreach (HttpCookie item in cookieCollection)
                    {
                        filter.CookieManager.SetCookie(item, false);
                    }
                    request.Dispose();
                    request  = new HttpRequestMessage(HttpMethod.Get, new Uri("http://172.24.39.253/portal/logon.htm"));
                    response = await httpClient.SendRequestAsync(request);

                    if (response.StatusCode == HttpStatusCode.Ok)
                    {
                        if (responseString.Contains("value='Logoff'"))
                        {
                            await new MessageDialog("认证成功").ShowAsync();
                            Frame.Navigate(typeof(MainPage));
                            Frame.Navigate(typeof(Login));
                        }
                        else if (responseString.Contains("pt_unload()"))
                        {
                            await new MessageDialog("已登录 ").ShowAsync();
                        }
                        else
                        {
                            await new MessageDialog("认证失败,请检查用户名或密码").ShowAsync();
                        }
                    }
                    else
                    {
                        await new MessageDialog(response.StatusCode.ToString()).ShowAsync();
                    }
                }

                catch (Exception ex)
                {
                    await new MessageDialog("wifi连接可能未就绪,请稍后重试").ShowAsync();
                }
                finally
                {
                    if (httpClient != null)
                    {
                        httpClient.Dispose();
                    }
                    if (request != null)
                    {
                        request.Dispose();
                    }
                    ;
                    if (postData != null)
                    {
                        postData.Dispose();
                    }
                    if (response != null)
                    {
                        response.Dispose();
                    }
                    if (filter != null)
                    {
                        filter.Dispose();
                    }
                }
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 15
0
        private async Task GetWebServiceDataAsync()
        {
            try
            {
                string requestUrl = "http://replatform.cloudapp.net:8000/getguess/?uuid={0}&type={1}&page={2}&from={3}&to={4}&r={5}";
                //string requestUrl = "http://192.168.1.215:9999/getguess/?uuid={0}&page={1}";
                string userid = App.gDeviceName;
                string type = App.gDeviceType;
                Random random = new Random();
                int page = defaultPageValue;//random.Next(iMinInclusivePageValue, iMaxExclusivePageValue);
                int r = random.Next();
                requestUrl = String.Format(requestUrl, userid, type, page, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo(), r);

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);
                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                GetResultJsonData(jsonText);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }
            }
            catch(Exception) {}
        }