Code Examples:
-
Calling the Service using C#
The following is a code example of how to make a call to the service using C#. The service uses basic authentication mode More Info..using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.IO; namespace ConsoleApplication { class Program { static void Main(string[] args) { string url = string.Format("{0}/Validation?stencils={1}", System.Configuration.ConfigurationManager.AppSettings["URLREST"], "12345,23456"); string details = CallRestMethod(url); } public static string CallRestMethod(string url) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url); webrequest.Method = "GET"; webrequest.ContentType = "application/json; charset=utf-8"; webrequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes( System.Configuration.ConfigurationManager.AppSettings["USERNAME"] + ":" + System.Configuration.ConfigurationManager.AppSettings["PASSWORD"])); HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); Encoding enc = System.Text.Encoding.GetEncoding("utf-8"); StreamReader responseStream = new StreamReader(webresponse.GetResponseStream(), enc); string result = string.Empty; result = responseStream.ReadToEnd(); webresponse.Close(); return result; } } }