Visual Studio .NET - Too many automatic redirections -HTTPWebRequest

Asked By Peter Bromberg on 09-Sep-01 11:56 AM
I'm experimenting with some c# webservice code that is designed to return the most recent say, 3 days of "HOWTOS"
from the MS Search service.

Here is a sample working GET URL. You can paste this into IE and it will return a result page. (sorry about any wrapping):

-- My problem is that in a webservice call:

HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(serverURL);
      HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
      StreamReader strm = new StreamReader(webresp.GetResponseStream(),
      StringBuilder strContent = new StringBuilder("");
      sContentTemp = strm.ReadToEnd();
      string contents=strContent.ToString();

-- this returns the following exception:

System.Net.WebException: Too many automatic redirections attempted.
   at System.Net.HttpWebRequest.CheckFinalStatus()
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.HttpWebRequest.GetResponse()
   at MSInfoService.GetInfo(String sType, String sDays)

Anybody got any ideas?

MaximumAutomaticRedirections Property - Asked By Dexter Dotnetsky on 11-Sep-01 01:56 PM

The Uri you access wants you to set
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(serverURL);
webreq.UserAgent="Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.0)"

HttpWebrequest has a property MaximumAutomaticRedirections that is set to 30 or so by default.