C#: HttpWebRequest.GetResponse() changing URI?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • namit101
    New Member
    • Feb 2008
    • 7

    C#: HttpWebRequest.GetResponse() changing URI?

    When I create an HttpWebRequest, it seems to have the right uri to access the website (with the GET variables there too). But as soon as I run request.GetResp onse() the URL changes such that it no longer includes the GET variables and it uses that new uri for accessing the server. Anyone know what might be the problem?


    Code:
    string url = "http://internal.company.com?var1=x&var2=y";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    
    request.Timeout = timeout;
                    
    request.UserAgent = "UserAgentName";               
    request.Headers.Add("Accept-Encoding", "gzip, deflate");
    request.UseDefaultCredentials = true;
    request.CookieContainer = new CookieContainer();
    
    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
    //Console.WriteLine(response.StatusDescription);
    using (Stream dataStream = GetStream(response))
    {
    using (StreamReader reader = new StreamReader(dataStream, Encoding.UTF8))
    {
    							string data = reader.ReadToEnd();
    							//Console.WriteLine(data);
    							return data;
    						}
    					}
    				}
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    (Not sure how this one slipped by me before)

    Did you figure this out? What do you mean by "GET" variables?
    Sometimes when you make a request to a server it returns the status saying "resource has moved, can now be found here:<location> " and the HttpWebRequest will automatically try the address given for <location>.
    Is that what you ment?

    Comment

    • namit101
      New Member
      • Feb 2008
      • 7

      #3
      After turning off automatic redirection, I realized that the server was sending me to another location (which changed my uri in the httpwebrequest) . The original problem was related to using the right cookie container/credentials (now fixed).

      Comment

      Working...