An easy way to create a service, add headers and read a JSON response,
private static void WebRequest() { const string WEBSERVICE_URL = "<<Web service URL>>"; try { var webRequest = System.Net.WebRequest.Create(WEBSERVICE_URL); if (webRequest != null) { webRequest.Method = "GET"; webRequest.Timeout = 12000; webRequest.ContentType = "application/json"; webRequest.Headers.Add("Authorization", "Basic dchZ2VudDM6cGFdGVzC5zc3dvmQ="); using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream()) { using (System.IO.StreamReader sr = new System.IO.StreamReader(s)) { var jsonResponse = sr.ReadToEnd(); Console.WriteLine(String.Format("Response: {0}", jsonResponse)); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
Lucky May 25 '16 at 7:46 a.m. 2016-05-25 07:46 a.m.
source share