/// <summary>
        /// Obtiene el resultado en formato json de la llamada al api
        /// </summary>
        /// <param name="htmlContent">contenido html</param>
        /// <param name="ocurrence">Posición de la cual hay que mirar</param>
        /// <returns>resultado de la llamada en formato json</returns>
        private string Api(string htmlContent, int ocurrence)
        {
            int first = htmlContent.IndexOf(DirectivesList.Api, ocurrence);

            first = first + DirectivesList.Api.Length;
            int         last  = htmlContent.IndexOf(DirectivesList.EndDirective, first);
            string      url   = htmlContent.Substring(first, last - first).Trim();
            TokenBearer token = null;

            if (url.Contains(_configUrlService.GetUrl()) || url.Contains("{URL_APICARGA}"))
            {
                url   = url.Replace("{URL_APICARGA}", _configUrlService.GetUrl());
                token = _callTokenService.CallTokenCarga();
            }
            else if (url.Contains(_configUrlService.GetUrlDocumentacion()) || url.Contains("{URL_DOCUMENTACION}"))
            {
                url   = url.Replace("{URL_DOCUMENTACION}", _configUrlService.GetUrlDocumentacion());
                token = _callTokenService.CallTokenApiDocumentacion();
            }
            else if (url.Contains(_configUrlCronService.GetUrl()) || url.Contains("{URL_CRON}"))
            {
                url   = url.Replace("{URL_CRON}", _configUrlCronService.GetUrl());
                token = _callTokenService.CallTokenCron();
            }
            string result = _callService.CallGetApi(url, "", token);

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Hace una petición delete al apiCron
        /// </summary>
        /// <param name="urlBase">Url donde se encuentra el api cron, se puede omitir en este método</param>
        /// <param name="urlMethod">Url del método dentro del apiCron</param>
        /// <param name="token">token bearer de seguridad</param>
        public string CallDeleteApi(string urlBase, string urlMethod, TokenBearer token = null)
        {
            string result = "";
            HttpResponseMessage response = null;

            try
            {
                HttpClient client = new HttpClient();
                if (token != null)
                {
                    client.DefaultRequestHeaders.Add("Authorization", $"{token.token_type} {token.access_token}");
                }
                string url = _serviceUrl.GetUrl();
                response = client.DeleteAsync($"{url}{urlMethod}").Result;
                response.EnsureSuccessStatusCode();
                result = response.Content.ReadAsStringAsync().Result;
            }
            catch (HttpRequestException)
            {
                if (!string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result))
                {
                    throw new HttpRequestException(response.Content.ReadAsStringAsync().Result);
                }
                else
                {
                    throw new HttpRequestException(response.ReasonPhrase);
                }
            }
            return(result);
        }
        public string CallDeleteApi(string urlMethod)
        {
            string result = "";
            HttpResponseMessage response = null;

            try
            {
                HttpClient client = new HttpClient();
                string     url    = _serviceUrl.GetUrl();
                response = client.DeleteAsync($"{url}{urlMethod}").Result;
                response.EnsureSuccessStatusCode();
                result = response.Content.ReadAsStringAsync().Result;
            }
            catch (HttpRequestException)
            {
                if (!string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result))
                {
                    throw new HttpRequestException(response.Content.ReadAsStringAsync().Result);
                }
                else
                {
                    throw new HttpRequestException(response.ReasonPhrase);
                }
            }
            return(result);
        }