I'm using the below code to get the authorization header from a url but the authorization field is always returned as null
string url = "https://xyz.appdirect.com/api/integration/v1/events/abc-123";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
string value = httpWebRequest.Headers["Authorization"];
Also when i followed the MSDN code, i am getting a null value for the headers
WebRequest request = WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
NameValueCollection authHeader = request.Headers;
if (authHeader.Count > 0)
{
foreach (string strKey in authHeader)
{
string s = strKey + " = " + request.Headers[strKey] + "<br />\n";
Console.WriteLine(String.Format(" Key Value header: {0}", authHeader[strKey]));
}
}
else
{
Console.WriteLine(String.Format("No headers found"));
}
What is the correct way to get the authorization header?