Esempio n. 1
0
        private async void programO(string Input, bool key)
        {
            string url = "http://api.program-o.com/v2/chatbot/";
            var    deviceInformation = new EasClientDeviceInformation();
            string Id = deviceInformation.Id.ToString();

            if (Input == "" || Input.Replace(" ", "") == "")
            {
                if (key == false)
                {
                    Input             = "Hi!";
                    txtOutputTwo.Text = Input;
                }
                else
                {
                    Input = "Hi!";
                }
            }
            else
            {
                txtOutputTwo.Text = Input;
            }

            string param = "?bot_id=6&convo_id=sam" + Id.Substring(0, 12) + "&format=json&say=" + Input;

            // Send Request
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
            Uri requestUri = new Uri(url + param);

            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                JsonObject root = JsonValue.Parse(httpResponseBody).GetObject();
                string     text = Convert.ToString(root["botsay"]);

                txtOutput.Text = ((text.Replace("\"", "")).Replace("Program-O", "Sam")).Replace("\\", "");
            }
            catch
            {
                Random r  = new Random();
                int    nr = r.Next(1, 3);
                if (nr == 1)
                {
                    txtOutput.Text = "Check your internet connection!";
                }
                else
                {
                    txtOutput.Text = "Error can't connect to my ship!";
                }
            }

            txtInput.Text = "";
        }
Esempio n. 2
0
        public async Task <string> GetGardenTeacher(string email, string type)
        {
            string completeUri = "http://childappapiservice.azurewebsites.net/api/users?email=" + email
                                 + "&type=" + type;
            Uri requestUri = new Uri(completeUri);

            Windows.Web.Http.HttpClient          httpClient   = new Windows.Web.Http.HttpClient();
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                                //Send the GET request
                                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                user getUser = ReadToObjectUser(httpResponseBody);
                return(getUser.email);
            }
            catch (Exception ex)
            {
                return("");
            }
        }
Esempio n. 3
0
        public async Task <string> GetParentContactAsync(string email)
        {
            string completeUri = "http://childappapiservice.azurewebsites.net/api/contacts?Parentemail=" + email
                                 + "&isParent=true";
            Uri requestUri = new Uri(completeUri);

            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();

            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                string childEmail = JsonConvert.DeserializeObject <string>(httpResponseBody);
                return(childEmail);
            }

            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets connection level for the current Wifi Connection.
        /// </summary>
        /// <returns> string value of level/></returns>
        ///
        public static async Task <bool> GetNetworkLevelUsingGoogle()
        {
            if (!headers.UserAgent.TryParseAdd(WP_USER_AGENT))
            {
                throw new Exception("Invalid header value: " + WP_USER_AGENT);
            }
            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(new Uri(checkInternetUriString));

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
            }
            catch
            {
                return(false);
            }
            var succes   = httpResponseBody.Contains("authlogin");
            var gSuccess = httpResponseBody.Contains("Google");

            if (!succes)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
        public static async Task <HtmlDocument> GetHtmlDoc(string relativeUri)
        {
            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            Windows.Web.Http.HttpClient httpClient         = new Windows.Web.Http.HttpClient();
            HttpRequestMessage          HttpRequestMessage =
                new HttpRequestMessage(HttpMethod.Get,
                                       new Uri(DataSource.requestUri, relativeUri));

            HttpRequestMessage.Headers.Add("User-Agent", DataSource.CustomUserAgent);
            try
            {
                //Send the GET request
                httpResponse = await httpClient.SendRequestAsync(HttpRequestMessage);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(httpResponseBody);
            return(htmlDoc);
        }
Esempio n. 6
0
        public async Task <symbol[]> GetUserCounterAsync(symbol userSymbol)
        {
            string completeUri = "http://childappapiservice.azurewebsites.net/api/counters?email="
                                 + userSymbol.email + "&symbolName=" + userSymbol.symbolName;

            Uri requestUri = new Uri(completeUri);

            Windows.Web.Http.HttpClient          httpClient   = new Windows.Web.Http.HttpClient();
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                symbol[] userSymbolUsage = JsonConvert.DeserializeObject <symbol[]>(httpResponseBody);

                return(userSymbolUsage);
            }

            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 7
0
        //private void GroupItemsPage_SizeChange(object sender, SizeChangedEventArgs e)
        //{
        //    if (e.NewSize.Width < 500)
        //    {
        //        VisualStateManager.GoToState(this, "MinimalLayaout", true);
        //    }
        //    else if (e.NewSize.Width < e.NewSize.Height)
        //    {
        //        VisualStateManager.GoToState(this, "PortraitLayout", true);
        //    }
        //    else
        //    {
        //        VisualStateManager.GoToState(this, "DefaultLayaout", true);
        //    }
        //}

        //this method get json data from page and save those at observablecolletion
        private async Task TryPostJsonAsync()
        {
            currentpage = 1;
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
            var headers    = httpClient.DefaultRequestHeaders;
            Uri requestUri = new Uri("https://www.reddit.com//top/.json");

            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                var obj = JsonConvert.DeserializeObject <Model.RootObject>(httpResponseBody, new JsonSerializerSettings()
                {
                    Culture = CultureInfo.CurrentCulture
                });

                collectionItemsData2 = new ObservableCollection <Data2>((from r in obj.data.children
                                                                         select r.data).ToList());
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
        }
Esempio n. 8
0
        public static async Task <string> LoginSucess(string access_token)
        {
            Windows.Web.Http.HttpClient hc = new Windows.Web.Http.HttpClient();
            access_key = access_token;
            Windows.Web.Http.HttpResponseMessage hr2 = await hc.GetAsync(new Uri("http://api.bilibili.com/login/sso?&access_key=" + access_token + "&appkey=422fd9d7289a1dd9&platform=wp"));

            hr2.EnsureSuccessStatusCode();

            SettingHelper.Set_Access_key(access_token);
            //看看存不存在Cookie
            HttpBaseProtocolFilter hb = new HttpBaseProtocolFilter();
            HttpCookieCollection   cookieCollection = hb.CookieManager.GetCookies(new Uri("http://bilibili.com/"));

            List <string> ls = new List <string>();

            foreach (HttpCookie item in cookieCollection)
            {
                ls.Add(item.Name);
            }
            if (ls.Contains("DedeUserID"))
            {
                if (Logined != null)
                {
                    Logined(null, null);
                }
                return("登录成功");
            }
            else
            {
                return("登录失败");
            }
        }
Esempio n. 9
0
        public async Task <user> GetUserByMailAsync(string email)
        {
            string completeUri = "http://childappapiservice.azurewebsites.net/api/users?email=" + email;
            Uri    requestUri  = new Uri(completeUri);

            Windows.Web.Http.HttpClient          httpClient   = new Windows.Web.Http.HttpClient();
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                user getUser = ReadToObject(httpResponseBody);
                return(getUser);
            }

            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 10
0
        public async Task <user[]> GetGardenChildren(string garden)
        {
            string completeUri = "http://childappapiservice.azurewebsites.net/api/users?garden=" + garden;

            Uri requestUri = new Uri(completeUri);

            Windows.Web.Http.HttpClient          httpClient   = new Windows.Web.Http.HttpClient();
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                user[] gardenUsers = JsonConvert.DeserializeObject <user[]>(httpResponseBody);

                return(gardenUsers);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 11
0
        public async Task <List <Uposlenik> > dajSveUposlenike()
        {
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();

            var headers = httpClient.DefaultRequestHeaders;

            string header = "ie";

            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            header = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36";
            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            string url        = "http://localhost:50180/Uposleniks/GetSve";
            Uri    requestUri = new Uri(url);

            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();

            string httpResponseBody = "";

            try
            {
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                string json = httpResponseBody;

                JsonConverter[] converters = { new UposlenikConverter() };
                var             test       = JsonConvert.DeserializeObject <List <Uposlenik> >(json, new JsonSerializerSettings()
                {
                    Converters = converters
                });

                return(test);
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
            return(null);
        }
Esempio n. 12
0
        public async Task <string> getConnectToTranslateAsync(string queryString)
        {
            //Create an HTTP client
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
            //Add a user-agent header to the GET request.
            var headers = httpClient.DefaultRequestHeaders;
            //The safe way to add a header value is to use the TryParseAdd method and verify the return value is true,
            //especially if the header value is coming from user input.
            string header = "ie";

            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }
            header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }
            //appid+q+salt+密钥
            Uri requestUri = new Uri("http://api.fanyi.baidu.com/api/trans/vip/translate?q="
                                     + queryString
                                     + "&from=en&to=zh&appid=20180424000149859&salt=1435660288&sign=" + GetMD5WithString(get_uft8("20180424000149859" + queryString + "1435660288" + "Jwjp6uJTHbN2YUX7DwNW")));

            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                //"{\"from\":\"en\",\"to\":\"zh\",\"trans_result\":[{\"src\":\"apple\",\"dst\":\"\\u82f9\\u679c\"}]}"
                res = httpResponseBody.ToString();
                JsonObject temp  = JsonObject.Parse(res);
                JArray     jlist = JArray.Parse(temp["trans_result"].ToString());
                //jp = (JsonObject)JsonConvert.DeserializeObject(res);
                return(jlist[0]["dst"].ToString());
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
                return(httpResponseBody);
            }
        }
Esempio n. 13
0
        public async Task GetTest()
        {
            //Create an HTTP client object
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();

            //Add a user-agent header to the GET request.
            var headers = httpClient.DefaultRequestHeaders;

            //The safe way to add a header value is to use the TryParseAdd method and verify the return value is true,
            //especially if the header value is coming from user input.
            string header = "ie";

            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            Uri requestUri = new Uri("https://prodigalcompany.com/npjTest/SurveyStuff/testSurveyFile.json");

            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                Debug.WriteLine("Output: " + httpResponseBody);
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
        }
Esempio n. 14
0
        private async void DowmButton_Click(object sender, RoutedEventArgs e)
        {
            Uri uri;
           if (textbox.Text == "")
           {
                uri = new Uri("http://www.neu.edu.cn/indexsource/neusong.mp3");
            }
            else
                uri = new Uri(textbox.Text);
            string Filename = System.IO.Path.GetFileName(uri.LocalPath);

            StorageFile file = await KnownFolders.MusicLibrary.CreateFileAsync(Filename,CreationCollisionOption.ReplaceExisting);

            HttpClient httpClient = new HttpClient();
            HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";
            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(uri);
                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
                var sourceStream= await httpResponse.Content.ReadAsInputStreamAsync();
                    using (var destinationStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        using (var destinationOutputStream = destinationStream.GetOutputStreamAt(0))
                        {
                            await RandomAccessStream.CopyAndCloseAsync(sourceStream, destinationStream);
                        }
                    }

                var stream1 = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
                mediaplayer.SetSource(stream1, file.ContentType);
                mediaplayer.Play();
                filename.Text = Filename;

            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }

        }
Esempio n. 15
0
        /*
         * ----< Function > TruncateTestFunctions
         * ----< Description >
         * This function will truncate any items in the test function table of the api database
         * ----< Description >
         * @Param None
         * @Return None
         */
        public static async void TruncateTestFunctions()
        {
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();

            Windows.Web.Http.Headers.HttpRequestHeaderCollection headers = httpClient.DefaultRequestHeaders;

            string header = "ie";

            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            Uri requestUri = new Uri("http://www.kaminfay.com/");

            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                Debug.WriteLine(httpResponseBody);
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
        }
Esempio n. 16
0
        public async Task <string> getConnectToGetWeatherAsync(string queryString)
        {
            //Create an HTTP client
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
            //Add a user-agent header to the GET request.
            var headers = httpClient.DefaultRequestHeaders;
            //The safe way to add a header value is to use the TryParseAdd method and verify the return value is true,
            //especially if the header value is coming from user input.
            string header = "ie";

            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }
            header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }
            //Uri requestUri = new Uri("http://v.juhe.cn/weather/index?format=2&cityname="+queryString+"&key=c8f3ebd5bd91ab7aa0a9be9cc717e5dd");
            Uri requestUri = new Uri("http://v.juhe.cn/weather/index?cityname=" + queryString + "&dtype=xml&format=2&key=c8f3ebd5bd91ab7aa0a9be9cc717e5dd");

            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                return(queryString + ":" + getStringFromWeatherXMLString(httpResponseBody));
            } catch (Exception ex) {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
                return(res);
            }
        }
Esempio n. 17
0
        private async void DownLoadButton_Click(object sender, RoutedEventArgs e)
        {
            Uri uri = new Uri(MyBox.Text);

            MyMediaPlayer.Source = uri;
            string FileName = System.IO.Path.GetFileName(uri.LocalPath);


            var httpClient   = new HttpClient();
            var httpResponse = new Windows.Web.Http.HttpResponseMessage();
            var file         = await KnownFolders.MusicLibrary.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);

            string httpResponseBody = "";

            try
            {
                httpResponse = await httpClient.GetAsync(uri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                var sourceStream = await httpResponse.Content.ReadAsInputStreamAsync();

                using (var destinationStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (var destinationOutputStream = destinationStream.GetOutputStreamAt(0))
                    {
                        await RandomAccessStream.CopyAndCloseAsync(sourceStream, destinationStream);
                    }
                }
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                MyMediaPlayer.SetSource(stream, file.ContentType);
                MyMediaPlayer.Play();
            }
            catch { }
        }
Esempio n. 18
0
        public static async Task <string> Logout()
        {
            if (!headers.UserAgent.TryParseAdd(WP_USER_AGENT))
            {
                throw new Exception("Invalid header value: " + WP_USER_AGENT);
            }
            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.GetAsync(new Uri(logoutUriString));

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
                return(httpResponseBody);
            }

            var exist = httpResponseBody.Contains("successfully");

            if (exist)
            {
                return("You have successfully logged out");
            }

            else
            {
                return("No active Session To Logout");
            }
        }
Esempio n. 19
0
        public async Task <Potrosac> dajPotrosaca(string jmbg)

        {
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();

            var headers = httpClient.DefaultRequestHeaders;

            string header = "ie";

            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            header = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36";
            if (!headers.UserAgent.TryParseAdd(header))
            {
                throw new Exception("Invalid header value: " + header);
            }

            string url = "http://localhost:50180/Potrosacs/GetJMBG?JMBG=" + jmbg;
            //Uri requestUri = new Uri("http://localhost:50180/Potrosacs/GetAccount?Email" + EMail + "&password="******"";

            try
            {
                httpResponse = await httpClient.GetAsync(requestUri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                string json = httpResponseBody;
                novi = JsonConvert.DeserializeObject <Potrosac>(json);

                return(novi);
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
            return(null);

            /*try
             * {
             *  Trazeni = null;
             *  Trazeni = await Task.Run(() => Baza.Instanca.dajPotrosaca(Jmbg));
             *
             *  if (Trazeni != null)
             *  {
             *      Found = true;
             *      var dialog = new MessageDialog("Uspjesno pronadjen potrosac!");
             *      await dialog.ShowAsync();
             *  }
             *  else
             *  {
             *      Found = false;
             *      var dialog = new MessageDialog("Nije pronadjen potrosac.");
             *      await dialog.ShowAsync();
             *  }
             * }
             * catch(Exception)
             * {
             *
             * }*/
        }
Esempio n. 20
0
        public static async Task <string> LoginBilibili(string UserName, string Password)
        {
            try
            {
                //https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=JPJclVQpH4jwouRcSnngNnuPEq1S1rizxVJjLTg%2FtdqkKOizeIjS4CeRZsQg4%2F500Oye7IP4gWXhCRfHT6pDrboBNNkYywcrAhbOPtdx35ETcPfbjXNGSxteVDXw9Xq1ng0pcP1burNnAYtNRSayEKC1jiugi1LKyWbXpYE6VaM%3D&type=json&userid=xiaoyaocz&sign=74e4c872ec7b9d83d3a8a714e7e3b4b3
                //发送第一次请求,得到access_key

                string url = "https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=" + WebUtility.UrlEncode(await GetEncryptedPassword(Password)) + "&type=json&userid=" + WebUtility.UrlEncode(UserName);
                url += "&sign=" + ApiHelper.GetSign(url);

                string results = await WebClientClass.GetResults(new Uri(url));

                //Json解析及数据判断
                LoginModel model = new LoginModel();
                model = JsonConvert.DeserializeObject <LoginModel>(results);
                if (model.code == -627)
                {
                    return("登录失败,密码错误!");
                }
                if (model.code == -626)
                {
                    return("登录失败,账号不存在!");
                }
                if (model.code == -625)
                {
                    return("密码错误多次");
                }
                if (model.code == -628)
                {
                    return("未知错误");
                }
                if (model.code == -1)
                {
                    return("登录失败,程序注册失败!请联系作者!");
                }
                Windows.Web.Http.HttpClient hc = new Windows.Web.Http.HttpClient();
                if (model.code == 0)
                {
                    access_key = model.access_key;
                    Windows.Web.Http.HttpResponseMessage hr2 = await hc.GetAsync(new Uri("http://api.bilibili.com/login/sso?&access_key=" + model.access_key + "&appkey=422fd9d7289a1dd9&platform=wp"));

                    hr2.EnsureSuccessStatusCode();

                    SettingHelper.Set_Access_key(model.access_key);
                }
                //看看存不存在Cookie
                HttpBaseProtocolFilter hb = new HttpBaseProtocolFilter();
                HttpCookieCollection   cookieCollection = hb.CookieManager.GetCookies(new Uri("http://bilibili.com/"));

                List <string> ls = new List <string>();
                foreach (HttpCookie item in cookieCollection)
                {
                    ls.Add(item.Name);
                }
                if (ls.Contains("DedeUserID"))
                {
                    return("登录成功");
                }
                else
                {
                    return("登录失败");
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147012867)
                {
                    return("登录失败,检查你的网络连接!");
                }
                else
                {
                    return("登录发生错误");
                }
            }
        }
Esempio n. 21
0
        public static async Task <string> Login()
        {
            var    error = "No credentials entered";
            string user, pass;

            try
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                user = localSettings.Values["user"].ToString();
                pass = localSettings.Values["pass"].ToString();
            }
            catch
            {
                return(error);
            }



            //string user = "******";
            //string pass = "******";
            var postContent = new HttpFormUrlEncodedContent(
                new KeyValuePair <string, string>[3] {
                new KeyValuePair <string, string>("serviceName", "ProntoAuthentication"),
                new KeyValuePair <string, string>("userId", user),
                new KeyValuePair <string, string>("password", pass)
            });

            //The safe way to add a header value is to use the TryParseAdd method and verify the return value is true,
            //especially if the header value is coming from user input.
            if (!headers.UserAgent.TryParseAdd(WP_USER_AGENT))
            {
                throw new Exception("Invalid header value: " + WP_USER_AGENT);
            }
            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = await httpClient.PostAsync(new Uri(loginString), postContent);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
                return(httpResponseBody);
            }
            NetworkConnectivityLevel _level = await Network.Pronto.GetNetworkLevel();

            var already = httpResponseBody.Contains("could");
            var exist   = httpResponseBody.Contains("account");
            var invalid = httpResponseBody.Contains("again");
            var succes  = httpResponseBody.Contains("Congratulations ");

            if (succes)
            {
                return("Login Succesful");
            }

            else if (invalid)
            {
                return("Invalid Credentials");
            }
            else if (already)
            {
                return("Already LoggedIn");
            }
            else
            {
                return("Sorry that Account does  Not Exist");
            }
        }
Esempio n. 22
0
        private async void Button_Click_Inscription(object sender, RoutedEventArgs e)
        {
            if (VerifFormulaire())
            {
                // recuperation des valeurs email et mdp
                Name      = name.Text;
                Firstname = firstname.Text;
                Email     = email.Text;
                Password  = password.Text;
                // recuperer la valeur du datepicker
                Birthdate = birthDatePicker.Date.Date.ToString("dd/MM/yyyy");

                if (McCheckBox.IsChecked == true)
                {// si la case parent est coché
                    IsParent = 1;
                }
                else
                {
                    IsParent = 0;
                }
                //Create an HTTP client object
                Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();

                //Add a user-agent header to the GET request.
                var headers = httpClient.DefaultRequestHeaders;

                //The safe way to add a header value is to use the TryParseAdd method and verify the return value is true,
                //especially if the header value is coming from user input.
                string header = "ie";
                if (!headers.UserAgent.TryParseAdd(header))
                {
                    throw new Exception("Invalid header value: " + header);
                }

                header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
                if (!headers.UserAgent.TryParseAdd(header))
                {
                    throw new Exception("Invalid header value: " + header);
                }

                Uri requestUri = new Uri("http://businesswallet.fr/Bmb/User_Inscription.php?name=" + Name + "&firstname=" + Firstname + "&birthdate=" + Birthdate + "&email=" + Email + "&password="******"&isparent=" + IsParent);

                //Send the GET request asynchronously and retrieve the response as a string.
                Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
                string httpResponseBody = "";

                try
                {
                    //Send the GET request
                    httpResponse = await httpClient.GetAsync(requestUri);

                    httpResponse.EnsureSuccessStatusCode();
                    httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                    user = JsonConvert.DeserializeObject <User>(httpResponseBody);
                }
                catch (Exception ex)
                {
                    httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
                }
                if (!(user is null))
                {
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(MainPage));
                }
            }
            else
            {
                libelleErreur.Text = "Veuillez remplir tout les champs pour vous inscrire";
            }
        }
Esempio n. 23
0
        public static async Task <string> LoginBilibili(string UserName, string Password)
        {
            try
            {
                //发送第一次请求,得到access_key
                WebClientClass wc      = new WebClientClass();
                string         results = await wc.GetResults(new Uri("https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=" + Password + "&type=json&userid=" + UserName));

                //Json解析及数据判断
                LoginModel model = new LoginModel();
                model = JsonConvert.DeserializeObject <LoginModel>(results);
                if (model.code == -627)
                {
                    return("登录失败,密码错误!");
                }
                if (model.code == -626)
                {
                    return("登录失败,账号不存在!");
                }
                if (model.code == -625)
                {
                    return("密码错误多次");
                }
                if (model.code == -628)
                {
                    return("未知错误");
                }
                if (model.code == -1)
                {
                    return("登录失败,程序注册失败!请联系作者!");
                }
                Windows.Web.Http.HttpClient hc = new Windows.Web.Http.HttpClient();
                if (model.code == 0)
                {
                    access_key = model.access_key;
                    Windows.Web.Http.HttpResponseMessage hr2 = await hc.GetAsync(new Uri("http://api.bilibili.com/login/sso?&access_key=" + model.access_key + "&appkey=422fd9d7289a1dd9&platform=wp"));

                    hr2.EnsureSuccessStatusCode();
                    StorageFolder folder = ApplicationData.Current.LocalFolder;
                    StorageFile   file   = await folder.CreateFileAsync("us.bili", CreationCollisionOption.OpenIfExists);

                    await FileIO.WriteTextAsync(file, model.access_key);
                }
                //看看存不存在Cookie
                HttpBaseProtocolFilter hb = new HttpBaseProtocolFilter();
                HttpCookieCollection   cookieCollection = hb.CookieManager.GetCookies(new Uri("http://bilibili.com/"));
                List <string>          ls = new List <string>();
                foreach (HttpCookie item in cookieCollection)
                {
                    ls.Add(item.Name);
                }
                if (ls.Contains("DedeUserID"))
                {
                    return("登录成功");
                }
                else
                {
                    return("登录失败");
                }
            }
            catch (Exception)
            {
                return("登录发生错误");
            }
        }