Exemple #1
0
        public static async Task <HttpResponseMessage> DeleteAsync(string tokenValue, string url, HttpContent content)
        {
            ResponseWithToken returnData = new ResponseWithToken();
            Auth_GetToken     tokens     = await GetFormTokenAsync(tokenValue);

            var message = new HttpRequestMessage(HttpMethod.Delete, url);

            message.Headers.Add("Cookie", "locale=en-US; .lcauth=" + tokenValue);
            message.Headers.Add("cookieToken", tokens.cookieToken);
            message.Headers.Add("formToken", tokens.formToken);

            message.Content = content;
            var result = await client.SendAsync(message);

            result.EnsureSuccessStatusCode();

            if (result.Headers.TryGetValues("Set-Cookie", out IEnumerable <string> cookieValues))
            {
                string setCookieValue = HttpUtility.UrlDecode(cookieValues.FirstOrDefault());
                Regex  regex          = new Regex("lcauth=(.*?);");
                var    v = regex.Match(setCookieValue);
                if (v != null)
                {
                    returnData.tokenValue = v.Groups[1].ToString();
                }
            }

            return(returnData.message);
        }
Exemple #2
0
        public static async Task <HttpResponseMessage> DeleteAsync(string tokenValue, string url)
        {
            Auth_GetToken tokens = await GetFormTokenAsync(tokenValue);

            var message = new HttpRequestMessage(HttpMethod.Delete, url);

            message.Headers.Add("Cookie", "locale=en-US; .lcauth=" + tokenValue);
            message.Headers.Add("cookieToken", tokens.cookieToken);
            message.Headers.Add("formToken", tokens.formToken);
            var result = await client.SendAsync(message);

            result.EnsureSuccessStatusCode();

            return(result);
        }
Exemple #3
0
        //Added by BBSR Team on 11th Jan 2018
        public static async Task <HttpResponseMessage> PostUserAsync(string url, HttpContent content)
        {
            ResponseWithToken returnData = new ResponseWithToken();
            Auth_GetToken     tokens     = await GetRegTokenAsync();

            var message = new HttpRequestMessage(HttpMethod.Post, url);

            message.Headers.Add("Cookie", "locale=en-US");
            message.Headers.Add("cookieToken", tokens.cookieToken);
            message.Headers.Add("formToken", tokens.formToken);
            message.Content = content;
            var result = await client.SendAsync(message);

            result.EnsureSuccessStatusCode();

            return(result);
        }
Exemple #4
0
        private static async Task <Auth_GetToken> GetRegTokenAsync()
        {
            ResponseWithToken returnData = new ResponseWithToken();

            var message = new HttpRequestMessage(HttpMethod.Get, "/api/Register/GetToken/");

            message.Headers.Add("Cookie", "locale=en-US; .lcauth=");

            var response = await client.SendAsync(message);

            response.EnsureSuccessStatusCode();

            string returnedData = await response.Content.ReadAsStringAsync();

            Auth_GetToken tokenValues = JsonConvert.DeserializeObject <Auth_GetToken>(returnedData);

            return(tokenValues);
        }
Exemple #5
0
        public static async Task <ResponseWithToken> PostAsync(string tokenValue, string url, HttpContent content)
        {
            Auth_GetToken tokens = await GetFormTokenAsync(tokenValue);

            var message = new HttpRequestMessage(HttpMethod.Post, url);

            message.Headers.Add("Cookie", "locale=en-US; .lcauth=" + tokenValue);
            message.Headers.Add("cookieToken", tokens.cookieToken);
            message.Headers.Add("formToken", tokens.formToken);
            message.Content = content;
            var result = await client.SendAsync(message);

            ResponseWithToken returnData = new ResponseWithToken();

            returnData.errorId = 0;
            //if (result.Headers.TryGetValues("Set-Cookie", out IEnumerable<string> cookieValues))
            //{
            //    string setCookieValue = HttpUtility.UrlDecode(cookieValues.FirstOrDefault());
            //    Regex regex = new Regex("lcauth=(.*?);");
            //    var v = regex.Match(setCookieValue);
            //    if (v != null)
            //    {
            //        returnData.tokenValue = v.Groups[1].ToString();
            //    }
            //}

            //returnData.message = result;

            //return returnData;



            if (result.IsSuccessStatusCode)
            {
                result.EnsureSuccessStatusCode();

                if (result.Headers.TryGetValues("Set-Cookie", out IEnumerable <string> cookieValues))
                {
                    string setCookieValue = HttpUtility.UrlDecode(result.Headers.GetValues("Set-Cookie").FirstOrDefault());
                    Regex  regex          = new Regex("lcauth=(.*?);");
                    var    v = regex.Match(setCookieValue);

                    if (v != null)
                    {
                        returnData.tokenValue = v.Groups[1].ToString();
                    }
                }
            }
            else
            {
                var responseAsString = await result.Content.ReadAsStringAsync();

                ErrorModel resultSet = JsonConvert.DeserializeObject <ErrorModel>(responseAsString);
                returnData.errorId      = resultSet.errorID;
                returnData.errorMessage = resultSet.message;
            }

            returnData.message = result;

            return(returnData);
        }