Example #1
0
        public EndpointConfig GetEndpointConfig(string username, string password)
        {
            FetchHomePage();

            EndpointConfig endpointConfig = null;


            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["HostUrl"] + "/Customer/Login");

            webRequest.ContentType = "application/json";
            webRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
            {
                CustomerLoginModel login = new CustomerLoginModel {
                    Username = username, Password = password
                };
                var loginjson = Newtonsoft.Json.JsonConvert.SerializeObject(login);

                streamWriter.Write(loginjson);
                streamWriter.Flush();
                streamWriter.Close();

                var httpResponse = (HttpWebResponse)webRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    endpointConfig = Newtonsoft.Json.JsonConvert.DeserializeObject <EndpointConfig>(result);
                }
            }

            return(endpointConfig);
        }
Example #2
0
        public EndpointConfig GetEndpointConfig(string username, string password)
        {
            FetchHomePage();

            EndpointConfig endpointConfig = null;

                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["HostUrl"] + "/Customer/Login");
                webRequest.ContentType = "application/json";
                webRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
            {
                CustomerLoginModel login = new CustomerLoginModel { Username = username, Password = password };
                var loginjson = Newtonsoft.Json.JsonConvert.SerializeObject(login);

                streamWriter.Write(loginjson);
                streamWriter.Flush();
                streamWriter.Close();

                var httpResponse = (HttpWebResponse)webRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    endpointConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<EndpointConfig>(result);
                }
            }

            return endpointConfig;
        }