0
votes

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)

2
What exception are you seeing?Rowland Shaw
Please see the update above. Thank you!user1288220

2 Answers

0
votes

Try setting HttpTestWebRequest.AllowAutoRedirect = true;

0
votes

There appears to be some specific HTTP header (google seems to send some duplicate cookie headers) on the landing page (http://www.google.com) which is causing this! Other sites/pages seem to load ok.