Ejemplo n.º 1
0
        public async Task <XmlDocument> get(string apiLocation)
        {
            CustomDelegatingHandler customDelegatingHandler = new CustomDelegatingHandler();
            HttpClient client = HttpClientFactory.Create(customDelegatingHandler);

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html"));
            HttpResponseMessage response = await client.GetAsync(apiLocation);

            if (response.IsSuccessStatusCode)
            {
                string xmlD = response.Content.ReadAsStringAsync().Result;
                Controller.ConsoleMessage.BlueMessage(xmlD);

                XmlDocument xml = JsonConvert.DeserializeXmlNode("{\"root\":" + xmlD + "}", "root");

                return(xml);
                //XmlDocument xmlDoc = await response.Content.ReadAsAsync<XmlDocument>();
                //return  JsonConvert.DeserializeXmlNode(xmlDoc);

                /*xml = new XmlDocument();
                 * xml.LoadXml(stringresponse);
                 * return xml;*/
            }
            return(null);
        }
Ejemplo n.º 2
0
        async Task <XmlDocument> RunAsync(Request request, string apiCall)
        {
            string apiAdress = Properties.Settings.Default.ServerAddress + ":" + Properties.Settings.Default.ServerPort + apiCall;

            CustomDelegatingHandler customeDelegatingHandler = new CustomDelegatingHandler();

            HttpClient          client   = HttpClientFactory.Create(customeDelegatingHandler);
            HttpResponseMessage response = await client.PutAsXmlAsync(apiAdress, request);

            if (response.IsSuccessStatusCode)
            {
                string responseString = await response.Content.ReadAsStringAsync();

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(responseString);
                return(xml);
            }
            return(null);
        }