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):
http://search.support.microsoft.com/kb/psssearch.asp?SPR=msall&KT;=ALL&T;=N&T1;
=3d&LQ;=HOWTO&PQ;=PastQuery&S;=F&A;=T&DU;=C&FR;=0&D;=support&LPR;=&LNG;=ENG&VR;=http%3
A%2F%2Fsupport.microsoft.com%2Fsupport%3Bhttp%3A%2F%2Fsupport.microsoft.com%
2Fservicedesks%2Fwebcasts%3Bhttp%3A%2F%2Fsupport.microsoft.com%2Fhighlights&
CAT=Support&VRL;=ENG&SA;=GN&Go.x;=34&Go.y;=20
-- 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(),
Encoding.ASCII);
      StringBuilder strContent = new StringBuilder("");
      sTemp="<MSInfoResponse>";
      sContentTemp = strm.ReadToEnd();
      strContent.Append(sContentTemp);
      string contents=strContent.ToString();
      strm.Close();
      sTemp+=contents+"</MSInfoResponse>";
      result=sTemp;
-- 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.