HttpWebRequest.AllowAutoRedirect

I’m trying to connect to a REST web service on a Panda II with the FEZ connect shield. The service requires a post back URI, which seams to be in conflict with the disabled AllowAutoRedirect. I’m at a bit of a lose trying to make this work…

This is simple HttpWebRequest and WebResponse.

The error I get on my response item is- NullReferenceException

ContentType ‘resp.ContentType’ threw an exception of type ‘System.NullReferenceException’ string

I’m making the assumption, that HttpWebRequest.AllowAutoRedirect = 0 is providing this error.


-		resp	{GHIElectronics.NETMF.Net.HttpWebResponse}	GHIElectronics.NETMF.Net.WebResponse {GHIElectronics.NETMF.Net.HttpWebResponse}
+		[GHIElectronics.NETMF.Net.HttpWebResponse]	{GHIElectronics.NETMF.Net.HttpWebResponse}	GHIElectronics.NETMF.Net.HttpWebResponse
		base	{GHIElectronics.NETMF.Net.HttpWebResponse}	System.MarshalByRefObject {GHIElectronics.NETMF.Net.HttpWebResponse}
		ContentLength	0	long
-		ContentType	'resp.ContentType' threw an exception of type 'System.NullReferenceException'	string {System.NullReferenceException}
-		base	{System.NullReferenceException}	System.SystemException {System.NullReferenceException}
-		base	{System.NullReferenceException}	System.Exception {System.NullReferenceException}
		_message	null	string
		InnerException	null	System.Exception
		m_HResult	2701131776	int {uint}
		m_innerException	null	System.Exception
+		m_stackTrace	{byte[16]}	object {byte[]}
		Message	"Exception was thrown: System.NullReferenceException"	string
		StackTrace	"GHIElectronics.NETMF.Net.HttpWebResponse::GetResponseHeader\r\nGHIElectronics.NETMF.Net.HttpWebResponse::get_ContentType\r\n"	string
+		Headers	null	GHIElectronics.NETMF.Net.WebHeaderCollection
+		ResponseUri	{GHIElectronics.NETMF.Net.Uri}	GHIElectronics.NETMF.Net.Uri



I wrote a simple php service without redirection, and the system works fine…

Any one have any thoughts on how I may over come this?

I am not sure if I got the answer but if you like here is the source code of the http library used with FEZ connect. Maybe you can fined answers over there.

You should check the response headers and handle any redirect requests that you get before trying to get the content type. You can put that logic in a do while loop.