Call External API from C# Class

Ankaprasad
Posted by Ankaprasad under C# category on | Points: 40 | Views : 829
string strurl = String.Format("http://Your url{0}", extQuoteId);
WebRequest requestobj = WebRequest.Create(strurl);
requestobj.Headers.Add("Authorization", <Replace with Auth code>);
requestobj.Method = "GET";
requestobj.ContentType = "application/json";
dynamic Jsondata = null;
string policyNumber = string.Empty;

using (WebResponse response = requestobj.GetResponse())
{
using (var sr = new StreamReader(response.GetResponseStream()))
{
string json = sr.ReadToEnd();
Jsondata = JsonConvert.DeserializeObject<dynamic>(json);
policyNumber = Jsondata.value;
}
}
char[] delimiters = new char[] { ':' };
string[] parts = policyNumber.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
string[] tempPolicy = parts[1].ToString().Split('}');
string tempPolicyNo = tempPolicy[0].ToString().Substring(1);
string policyNo = tempPolicyNo.Substring(0, tempPolicyNo.Length - 1);

return policyNo;

Comments or Responses

Login to post response