Esempio n. 1
0
        // POST: api/token
        public IHttpActionResult Post(ReqToken objToken)
        {
            try
            {
                string URL = "http://devsiempre.e3ecommerce.com/Api/token";

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(URL);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                //client.DefaultRequestHeaders.Add("X-VTEX-API-AppToken", Token);
                //client.DefaultRequestHeaders.Add("X-VTEX-API-AppKey", Key);

                /*
                 * ReqToken objToken = new ReqToken()
                 * {
                 *  username = "******",
                 *  password = "******",
                 *  grant_type = "siemprebien"
                 * };
                 */
                string Request = Newtonsoft.Json.JsonConvert.SerializeObject(objToken);

                HttpContent content = new StringContent(Request, UTF8Encoding.UTF8, "application/json");

                HttpRequestMessage reqMessage = null;
                //System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Ssl3;


                HttpResponseMessage response = client.PostAsync(new Uri(URL), content).Result;

                if (response.IsSuccessStatusCode)
                {
                    string    Respuesta = response.Content.ReadAsStringAsync().Result;
                    RespToken obj       = Newtonsoft.Json.JsonConvert.DeserializeObject <RespToken>(Respuesta);
                    return(Ok(obj));
                }
                else
                {
                    return(BadRequest("LOGIN INCORRECT"));
                }
            }
            catch (System.Exception ex)
            {
                return(null);
                //throw ex;
            }
        }
Esempio n. 2
0
        // POST: api/device
        //public IHttpActionResult Post(string hash, [FromBody]ReqDevice objDevice)
        public IHttpActionResult Post(string hash, string OS, string DeviceId)
        {
            try
            {
                //string URL = "http://devsiempre.e3ecommerce.com/Api/device?hash=" + hash;
                string URL = "http://devsiempre.e3ecommerce.com/Api/device?hash=" + hash + "&OS=" + OS + "&DeviceId=" + DeviceId;

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(URL);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //ReqDevice objDevice = new ReqDevice();
                //Hardcodeo para probar
                //objDevice.DeviceId = "qwewqeqwewq";
                //objDevice.OS = "IOS";
                //string Request = Newtonsoft.Json.JsonConvert.SerializeObject(objDevice);
                //HttpContent content = new StringContent(Request, UTF8Encoding.UTF8, "application/json");
                //HttpResponseMessage response = client.PostAsync(new Uri(URL), content).Result;
                HttpResponseMessage response = client.GetAsync(new Uri(URL)).Result;

                if (response.IsSuccessStatusCode)
                {
                    string    Respuesta = response.Content.ReadAsStringAsync().Result;
                    RespToken obj       = Newtonsoft.Json.JsonConvert.DeserializeObject <RespToken>(Respuesta);
                    return(Ok(obj));
                }
                else
                {
                    return(BadRequest("DeviceId not set."));
                }
            }
            catch (System.Exception ex)
            {
                return(null);
                //throw ex;
            }
        }