Пример #1
0
        public ObjectModel.ResultReponse GetRespone(string link, string token)
        {
            using (var wb = new WebClient())
            {
                ObjectModel.ResultReponse res = new ObjectModel.ResultReponse();
                try
                {
                    WebClient webClient = new WebClient();
                    webClient.Headers.Add("Authorization", token);

                    res.Result      = true;
                    res.ValueResult = webClient.DownloadString(link);
                }
                catch (Exception ex)
                {
                    res.Result      = false;
                    res.ValueResult = ex.Message;
                    res.ErorrResult = ex.Message;
                }
                return(res);
            }
        }
Пример #2
0
        public ObjectModel.ResultReponse PostRespone(string link, string token, string jsonData)
        {
            ObjectModel.ResultReponse res = new ObjectModel.ResultReponse();
            try
            {
                string    result    = string.Empty;
                WebClient webClient = new WebClient();

                var httpWebRequest = (HttpWebRequest)WebRequest.Create(link + "/?trungTamSangLocVm=");
                httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
                httpWebRequest.Headers.Add("Authorization", token);
                httpWebRequest.Method = "POST";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(jsonData);
                }

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();


                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    res.Result = true;
                }
                else
                {
                    res.ErorrResult = httpResponse.StatusDescription;
                }
            }
            catch (Exception ex)
            {
                res.Result      = false;
                res.ValueResult = ex.Message;
                res.ErorrResult = ex.Message;
            }
            return(res);
        }