I'm making a http request to google.com. This is the way I'm doing it:
HttpTestWebRequest = (HttpWebRequest)System.Net.WebRequest.Create("http://www.google.com/");
HttpTestWebRequest.Method = "GET";
HttpTestWebRequest.BeginGetResponse(GetHttpTestResponse, HttpTestWebRequest);
...
private void GetHttpTestResponse(IAsyncResult asynchronousResult)
{
var webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
WebResponse response =((HttpWebRequest)asynchronousResult.AsyncState).EndGetResponse(asynchronousResult);
...
}
With fiddler it gives me a http 302 moved status code, but in the app it throws me an exception and don't redirects to the new location of the website.
Any ideas why this is happening?
Update 1
Im getting a NullReferenceException
.
The stack trace is:
at System.Net.Browser.HttpWebRequestHelper.RemoveHttpOnlyCookies(Uri requestUri, String setCookieHeaderValue)
at System.Net.Browser.HttpWebRequestHelper.ParseHeaders(Uri requestUri, SecurityCriticalDataForMultipleGetAndSet`1 headers, WebHeaderCollection collection, Boolean removeHttpOnlyCookies, HttpStatusCode& status, String& statusDescription)
at System.Net.Browser.ClientHttpWebRequest.Progress(Object sender, EventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)