示例#1
0
        public async Task <HttpResponseMessage> Log <T>(T model, string bearerToken, string baseUrl, string referenceUrl)
        {
            StringContent stringContent = default(StringContent);
            string        jobj          = "";

            using (var client = new HttpClient())
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                client.BaseAddress = new Uri(baseUrl);
                if (!string.IsNullOrEmpty(bearerToken))
                {
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", bearerToken);
                }

                client.DefaultRequestHeaders.Add("AppId", URLConstants.AppId);
                if (model != null)
                {
                    jobj          = JsonConvert.SerializeObject(model);
                    stringContent = new StringContent(jobj, Encoding.UTF8, "application/json");
                }
                //hash using hashmac256
                string hash     = "";
                string uniqueid = GlobalStaticFields.GetUniqueID;
                hash = SHA.ComputeHMACSHA256(jobj, GlobalStaticFields.Customer.Email, uniqueid);
                //now add it to the header
                client.DefaultRequestHeaders.Add("CRC", hash);
                Analytics.TrackEvent($"Get Request {referenceUrl}");
                var request = await client.PostAsync(referenceUrl, stringContent);

                return(request);
            }
        }
示例#2
0
        public async Task <HttpResponseMessage> Get(string bearerToken, string baseUrl, string referenceUrl, string pageOrViewModel)
        {
            bearerToken = GlobalStaticFields.Token;
            using (var client = new HttpClient())
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

                client.BaseAddress = new Uri(baseUrl);
                if (!string.IsNullOrEmpty(bearerToken))
                {
                    client.DefaultRequestHeaders.Add("Authorization", $"Bearer {bearerToken}");
                }

                client.DefaultRequestHeaders.Add("AppId", URLConstants.AppId);
                client.DefaultRequestHeaders.Add("SwitchID", GlobalStaticFields.Customer?.Email);
                client.DefaultRequestHeaders.Add("ChannelID", "1");
                //hash using hashmac256
                string hash = "";
                //get unique ID
                string uniqueid = GlobalStaticFields.GetUniqueID;
                hash = SHA.ComputeHMACSHA256(referenceUrl, GlobalStaticFields.Customer?.Email, uniqueid);
                //now add it to the header
                client.DefaultRequestHeaders.Add("X-CRC", hash);
                var request = await client.GetAsync(referenceUrl);

                Analytics.TrackEvent($"Get Request {referenceUrl}");
                LogResponse(request, baseUrl, referenceUrl, "", pageOrViewModel);
                return(request);
            }
        }
示例#3
0
        public async Task <HttpResponseMessage> PostIBS <T>(T model, string bearerToken, string baseUrl, string referenceUrl, string pageOrViewModel, bool isSensitive = false)
        {
            StringContent stringContent = default(StringContent);
            string        jobj          = "";

            using (var client = new HttpClient())
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

                client.BaseAddress = new Uri(baseUrl);
                if (!string.IsNullOrEmpty(bearerToken))
                {
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", bearerToken);
                }

                client.DefaultRequestHeaders.Add("AppId", URLConstants.AppId);
                client.DefaultRequestHeaders.Add("SwitchID", GlobalStaticFields.Customer?.Email);
                var xml = Utilities.XmlSerializer <T>(model);

                var ibs = new IBSRequestContent
                {
                    Appid = URLConstants.AppId,
                    XML   = xml
                };

                if (ibs != null)
                {
                    jobj          = JsonConvert.SerializeObject(ibs);
                    stringContent = new StringContent(jobj, Encoding.UTF8, "application/json");
                }
                //hash using hashmac256
                string hash     = "";
                string uniqueid = GlobalStaticFields.GetUniqueID;
                hash = SHA.ComputeHMACSHA256(jobj, GlobalStaticFields.Customer.Email, uniqueid);
                //now add it to the header
                client.DefaultRequestHeaders.Add("CRC", hash);
                var request = await client.PostAsync(referenceUrl, stringContent);

                LogResponse(request, baseUrl, referenceUrl, jobj, pageOrViewModel, isSensitive);

                return(request);
            }
        }