RESTful web service testing

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
areiplinger
Posts: 3
Joined: Mon Aug 03, 2015 10:58 pm

RESTful web service testing

Post by areiplinger » Wed Sep 02, 2015 5:32 pm

Greetings forum,

I have a conundrum, as I have been charged with creating an automation framework for testing Web services for my project. Thing is they are not WSDL services, and follow a REST framework (no ASMX). So the article for testing web services (how-to-test-web-services-with-ranorex) isn't very useful as I do not know of a summary page to connect with to gather the methods.

I just need some sort of service that will send XML requests to a specified address, and retrieve and validate the results. In essence kinda like SOAP UI, but under one-unified platform like Ranorex (hopefully).

Thanks.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: RESTful web service testing

Post by krstcs » Wed Sep 02, 2015 5:56 pm

I use .NET inside Ranorex to get/post information to one of our services in order to generate objects for testing. I do NOT test the services with Ranorex. My services return JSON objects, so it would be different for XML. Just adjust as needed and call the correct method in your code.

Code: Select all

using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;

namespace LIB
{
	public static class Service
	{
		public static HttpResponseMessage GetFromService_RAW(Uri serviceUri) {
			using (HttpClient client = new HttpClient()) {
				client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
				client.DefaultRequestHeaders.Host = serviceUri.Host;
				
				return client.GetAsync(serviceUri).Result;
			}
		}
		public static T GetFromService<T>(Uri serviceUri) {
			HttpResponseMessage response = GetFromService_RAW(serviceUri);
			
			if (!response.IsSuccessStatusCode) {
				throw new HttpException(string.Format("Invalid response from service: Status Code = '{0}'; Reason = '{1}'", response.StatusCode, response.ReasonPhrase));
			}
			
			DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
			
			MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response.Content.ReadAsStringAsync().Result));
			
			return (T)serializer.ReadObject(ms);
		}
		public static String GetFromService_String(Uri serviceUri) {
			return GetFromService_RAW(serviceUri).ToString();
		}
		
		public static T1 PostToService<T1, T2>(Uri serviceUri, T2 sendObject) {
			using (HttpClient client = new HttpClient()) 
			{
				DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T2));
				
				MemoryStream ms = new MemoryStream();
				
				serializer.WriteObject(ms, sendObject);
				
				ms.Position = 0;
				
				StreamReader sr = new StreamReader(ms);
				StringContent content = new StringContent(sr.ReadToEnd(), Encoding.UTF8, "application/json");
				
				sr.Close();
				ms.Close();
				
				client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
				client.DefaultRequestHeaders.Add("RX","RX");
				client.DefaultRequestHeaders.Host = serviceUri.Host;
				
				HttpResponseMessage response = client.PostAsync(serviceUri, content).Result;
				
				if (!response.IsSuccessStatusCode) {
					throw new HttpException(string.Format("Invalid response from service: Status Code = '{0}'; Reason = '{1}'", response.StatusCode, response.ReasonPhrase));
				}
				
				serializer = new DataContractJsonSerializer(typeof(T1));
				
				ms = new MemoryStream(Encoding.UTF8.GetBytes(response.Content.ReadAsStringAsync().Result));
				
				return (T1)serializer.ReadObject(ms);
			}
		}
	}
}

Shortcuts usually aren't...

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: RESTful web service testing

Post by odklizec » Thu Sep 03, 2015 7:42 am

Hi,

Unfortunately, I too don't use REST, but SOAP 1.1 requests. I'm sending a predefined xml file, containing whole SOAP1.1 request and process the response. I'm not sure if the same will work with REST requests, but you can give it a try? Maybe it requires only small modifications ;)

Here is the code I'm using (including comparison of reference and actual response, using MS XmlDiffPath tool)...
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;

using System.Xml;
using System.Xml.Linq;
using System.Net;
using System.IO;
using Microsoft.XmlDiffPatch;

namespace OnDemandAut.Recordings
{
	public partial class WebService_Set:CodeModules.Common
    {
        /// <summary>
        /// This method gets called right after the recording has been started.
        /// It can be used to execute recording specific initialization code.
        /// </summary>
        private void Init()
        {
            // Your recording specific initialization code goes here.
        }

        /// <summary>
        /// Method to send SOAP 1.1 requests and process the response
        /// </summary>
        /// <param name="serviceURL">service URL</param>
        /// <param name="actionString">service action string</param>
        /// <param name="refSoapMessageFile">ref. SOAP message file to be send</param>
        /// <param name="refServiceResponseFile">ref. service response file</param>
        /// <param name="compareServiceResponse">bool flag to compare or not the actual response with ref. response file</param>
        public void TestWebServiceSoapMsg(string serviceURL, string actionString, string refSoapMessageFile, string refServiceResponseFile, bool compareServiceResponse)
        {
		    refSoapMessageFile = TestSuite.Current.Parameters["gp_DataDirectory"] + "\\" + refSoapMessageFile;
		    
		    string refSoapMessage = @File.ReadAllText(refSoapMessageFile);
		    XmlDocument soapEnvelopeXml = CreateSoapEnvelope(refSoapMessage);
		    HttpWebRequest webRequest = CreateWebRequest(serviceURL, actionString);
		    InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
		
		    // begin async call to web request.
		    IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
		
		    // suspend this thread until call is complete. You might want to
		    // do something usefull here like update your UI.
		    asyncResult.AsyncWaitHandle.WaitOne();
		
		    // get the response from the completed web request.
		    string soapResult;
		    try
		    {
				using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
			    {
			        using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
			        {
			            soapResult = rd.ReadToEnd();
			        }
			        //print-out rawxml output
			        Console.Write(soapResult);        
			        //convert rawxml soap output to xml
					var soapResultXml = XDocument.Parse(soapResult);		        
					Report.Info("service response",soapResultXml.ToString());
					//get StatusCode from webResponse
					HttpWebResponse httpResponse = (HttpWebResponse)webResponse;
					if (httpResponse.StatusCode == HttpStatusCode.OK)
					{
						//get responseCode from soapResultXml (success/failure)
						foreach (XElement xe in soapResultXml.Descendants("response"))
						{
						    var responseCode = xe.Element("responseCode").Value;
						    Report.Success("response code", "web service response code: " + responseCode.ToString());
						}
						if (compareServiceResponse)
						{
							//compare soapResultXml with reference string
						    refServiceResponseFile = TestSuite.Current.Parameters["gp_DataDirectory"] + "\\" + refServiceResponseFile;
							string refServiceResponse = @File.ReadAllText(refServiceResponseFile);
							if (!CompareXml(refServiceResponse,@soapResultXml.ToString(),@"c:\temp\xml.diff"))
							{
								Report.Failure("Web service response different than expected.");
							}
							else
							{
								Report.Success("Web service response compared and the same.");
							}
						}
					}
					else
					{
						Report.Failure("Web service failure", "Web service response: " + httpResponse.StatusCode.ToString());
					}
			    }	
		    }
		    catch(Exception e)
		    {
		    	Report.Failure("Web service failure", "Web service returns an exception...\r\n" + e.ToString());
		    }

		}

		private static HttpWebRequest CreateWebRequest(string url, string action)
		{
		    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
		    webRequest.Headers.Add("SOAPAction", action);
		    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
		    webRequest.Accept = "text/xml";
		    webRequest.Method = "POST";
		    return webRequest;
		}
		
		private static XmlDocument CreateSoapEnvelope(string refSoapMessage)
		{
		    XmlDocument soapEnvelop = new XmlDocument();
		    soapEnvelop.LoadXml(refSoapMessage);
		    return soapEnvelop;
		}
		

		private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
		{
		    using (Stream stream = webRequest.GetRequestStream())
		    {
		        soapEnvelopeXml.Save(stream);
		    }
		}
		
		/// <summary>
		/// compare xml strings - returns true if identical
		/// </summary>
		/// <param name="refXML">ref. XML file</param>
		/// <param name="cmpXML">actual XML file to compare</param>
		/// <param name="diffFileNameWithPath">path to output XML file with differences</param>
		public static bool CompareXml(string refXML, string cmpXML, string diffFileNameWithPath)
		{
			var node1 = XElement.Parse(refXML).CreateReader();
			var node2 = XElement.Parse(cmpXML).CreateReader();
			
			var result = new XDocument();
			using (XmlWriter writer = XmlWriter.Create(diffFileNameWithPath))
			{
				var diff = new Microsoft.XmlDiffPatch.XmlDiff(XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreChildOrder |XmlDiffOptions.IgnorePrefixes);
				bool validateIdentical = diff.Compare(node1, node2, writer);
				writer.Flush();
				writer.Close();
				
				return validateIdentical;
			}
        }
    }
}
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

NewLearner
Posts: 29
Joined: Wed Jan 15, 2014 3:32 pm

Re: RESTful web service testing

Post by NewLearner » Mon Dec 21, 2015 3:52 pm

Thank you odklizec, since im new to web testing i dont know how to use this code in my project..
If anyone knew easy way of webservice automation for beginner please let me know
thank you

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: RESTful web service testing

Post by krstcs » Mon Dec 21, 2015 4:28 pm

The EASIEST and BEST (in most situations) way is to use SoapUI, as it is designed for service testing (not just SOAP, but REST/XML/JSON as well).

Ranorex is a FUNCTIONAL UI test automation tool. It is not designed for testing services.

However, you CAN test services with it, but you MUST use .NET code to do so. It's not that hard, but if you aren't going to code, there's no way to do it.
Shortcuts usually aren't...

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: RESTful web service testing

Post by odklizec » Mon Dec 21, 2015 10:03 pm

Hi,

I agree with Kelly. SoapUI is probably the easiest way to test web services. The code I posted will most probably not work for you without some editing. And for this you need to understand it first.

The truth is, that SoapUI was originally used (and still is) both by our manual testers and developers. Some of our web service tests require certain manual configuration steps. So I first thought about combining configuration and SoapUI steps using Ranorex automation. But after some research, I decided to do entire web service testing via Ranorex and some C# code. It turned out to be much easier than I originally expected. Unfortunately, it definitely requires at least medium level of coding knowledge.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

alan722
Posts: 25
Joined: Mon Jan 12, 2015 1:34 pm

Re: RESTful web service testing

Post by alan722 » Thu Dec 24, 2015 9:22 am

We do Web Api Testing and the below is a little API testing Framework we've created.
We create this in visual studio and then just import the dll to our ranorex project and make use of it.
You will see that there's two methods each with 4 overloads.
Hope it helps :D

Code: Select all

public class HttpClientMethod
    {
        public static async Task<HttpResponseInfo> GetAsync(string url, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));
                    

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    var response = client.GetAsync(url).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        public static async Task<HttpResponseInfo> GetAsync(string url, List<CustomHeaders> customHeaderList, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    if (customHeaderList.Count > 0)
                    {
                        foreach (CustomHeaders header in customHeaderList)
                        {
                            if (string.IsNullOrEmpty(header.Value))
                            {
                                client.DefaultRequestHeaders.Add(header.Name, "");
                            }
                            else
                            {
                                client.DefaultRequestHeaders.Add(header.Name, header.Value);
                            }
                        }
                    }

                    var response = client.GetAsync(url).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        public static async Task<HttpResponseInfo> GetAsync(string url, List<QSParameters> queryStringParameterList, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    url += ParameterBuilder(queryStringParameterList);

                    var response = client.GetAsync(url).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        public static async Task<HttpResponseInfo> GetAsync(string url, List<CustomHeaders> customHeaderList, List<QSParameters> queryStringParameterList, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    if (customHeaderList.Count > 0)
                    {
                        foreach (CustomHeaders header in customHeaderList)
                        {
                            if (string.IsNullOrEmpty(header.Value))
                            {
                                client.DefaultRequestHeaders.Add(header.Name, "");
                            }
                            else
                            {
                                client.DefaultRequestHeaders.Add(header.Name, header.Value);
                            }
                        }
                    }

                    url += ParameterBuilder(queryStringParameterList);

                    var response = client.GetAsync(url).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        public static async Task<HttpResponseInfo> PostAsync(string url, object inputModel, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    string body = string.Empty;
                    if (inputModel.GetType().Equals(typeof(System.String)))
                        body = inputModel.ToString();
                    else
                        body = JsonConvert.SerializeObject(inputModel);

                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    var response = client.PostAsync(url, new StringContent(body, Encoding.UTF8, contentType)).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        public static async Task<HttpResponseInfo> PostAsync(string url, List<CustomHeaders> customHeaderList, object inputModel, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    string body = string.Empty;
                    if (inputModel.GetType().Equals(typeof(System.String)))
                        body = inputModel.ToString();
                    else
                        body = JsonConvert.SerializeObject(inputModel);

                    if (customHeaderList.Count > 0)
                    {
                        foreach (CustomHeaders header in customHeaderList)
                        {
                            if (string.IsNullOrEmpty(header.Value))
                            {
                                client.DefaultRequestHeaders.Add(header.Name, "");
                            }
                            else
                            {
                                client.DefaultRequestHeaders.Add(header.Name, header.Value);
                            }
                        }
                    }

                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    var response = client.PostAsync(url, new StringContent(body, Encoding.UTF8, contentType)).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        public static async Task<HttpResponseInfo> PostAsync(string url, List<QSParameters> queryStringParameterList, object inputModel, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    string body = string.Empty;
                    if (inputModel.GetType().Equals(typeof(System.String)))
                        body = inputModel.ToString();
                    else
                        body = JsonConvert.SerializeObject(inputModel);

                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    url += ParameterBuilder(queryStringParameterList);

                    var response = client.PostAsync(url, new StringContent(body, Encoding.UTF8, contentType)).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        public static async Task<HttpResponseInfo> PostAsync(string url, List<CustomHeaders> customHeaderList, List<QSParameters> queryStringParameterList, object inputModel, string accessToken = "", string contentType = "application/json")
        {
            HttpResponseInfo httpResponseInfo = new HttpResponseInfo();
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    string body = string.Empty;
                    if (inputModel.GetType().Equals(typeof(System.String)))
                        body = inputModel.ToString();
                    else
                        body = JsonConvert.SerializeObject(inputModel);

                    if (customHeaderList.Count > 0)
                    {
                        foreach (CustomHeaders header in customHeaderList)
                        {
                            if (string.IsNullOrEmpty(header.Value))
                            {
                                client.DefaultRequestHeaders.Add(header.Name, "");
                            }
                            else
                            {
                                client.DefaultRequestHeaders.Add(header.Name, header.Value);
                            }
                        }
                    }

                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

                    if (!string.IsNullOrEmpty(accessToken))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    }

                    url += ParameterBuilder(queryStringParameterList);

                    var response = client.PostAsync(url, new StringContent(body, Encoding.UTF8, contentType)).Result;

                    httpResponseInfo.StatusCode = Convert.ToInt32(response.StatusCode);
                    httpResponseInfo.StatusDescription = response.ReasonPhrase;
                    httpResponseInfo.Content = await response.Content.ReadAsStringAsync();

                    return httpResponseInfo;
                }
                catch (Exception ex)
                {
                    httpResponseInfo.StatusCode = 500;
                    httpResponseInfo.StatusDescription = "HttpUtil Class Exception";
                    httpResponseInfo.Content = ex.ToString();
                    return httpResponseInfo;
                }
            }
        }

        private static string ParameterBuilder(List<QSParameters> parameterList)
        {
            string parameters = "?";

            if (parameterList.Count > 0)
            {
                for (int i = 0; i < parameterList.Count; i++)
                {
                    if (string.IsNullOrEmpty(parameterList[i].Value))
                    {
                        parameters += parameterList[i].Name;
                    }
                    else
                    {
                        parameters += parameterList[i].Name + "=" + parameterList[i].Value;
                    }

                    if (i != parameterList.Count - 1)
                    {
                        parameters += "&";
                    }
                }
            }

            return parameters;
        }
    }	
	public class QSParameters
	{
		public string Name { get; set; }
		public string Value { get; set; }
		
		public QSParameters(string paramName)
		{
			this.Name = paramName;
			this.Value = string.Empty;
		}
		
		public QSParameters(string paramName, string paramValue)
		{
			this.Name = paramName;
			this.Value = paramValue;
		}
	}
	
	public class CustomHeaders
	{
		public string Name { get; set; }
		public string Value { get; set; }
		
		public CustomHeaders(string headerName)
		{
			this.Name = headerName;
			this.Value = string.Empty;
		}
		
		public CustomHeaders(string headerName, string headerValue)
		{
			this.Name = headerName;
			this.Value = headerValue;
		}
	}
	
	public class HttpResponseInfo
	{
		public int StatusCode { get; set; }
		public string StatusDescription { get; set; }
        public string Content { get; set; }
	}