Object reference not set to an instance of an object request.GetResponse()
<pre><code>public static string Method_Name(
        string requestMethod, 
        string requestUrl, 
        string requestBody = null, 
        Dictionary&lt;string, string&gt; requestHeader = null, 
        string requestUserAgent = null, 
        Boolean isContentType = false)
    {

        string responseString = String.Empty;

        try
        {
            Uri requestUri = new Uri(requestUrl);
            WebRequest request = WebRequest.Create(requestUri);
            request.Timeout = 60000;

            if (requestHeader != null)
            {
                foreach (string key in requestHeader.Keys)
                {
                    request.Headers.Add(key, requestHeader[key]);
                }
            }

            request.Headers.Add("X-FD-TrustLevel", "trusted");
            request.Headers.Add("X-FD-Version", "1.0");

            request.Method = requestMethod;

            // For MAS 1.0 POST Call
            if (isContentType)
            {
                request.ContentType = @"application/json";
            }


            if (!String.IsNullOrEmpty(requestUserAgent))
            {
                ((HttpWebRequest)request).UserAgent = requestUserAgent;
            }

            if (!String.IsNullOrEmpty(requestBody))
            {
                Stream stream = request.GetRequestStream();
                string requestString = requestBody;
                stream.Write(Encoding.Default.GetBytes(requestString), 0, requestString.Length);
                stream.Close();
            }



/* ERROR */ HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))
            {
                responseString = responseStream.ReadToEnd();
            }



        }
        catch (Exception ex)
        {
            AnswersExceptionCollection.GetInstance().AddException(ex);
        }

        return responseString;
    }
}
</code></pre>

<p>I am getting the following message when code execution reaches <code>HttpWebResponse response = (HttpWebResponse)request.GetResponse();</code>:</p>

<blockquote>
  <p><em>Error occurred - Object reference not set to an instance of an object.</em> </p>
</blockquote>

<p>I am aware why this kind of error happens, but I am not able to find the root cause in this particular case. Any help will be much appreciated.</p>
