Results 1 to 2 of 2

Thread: Handling redirects with httpwebresponse

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Handling redirects with httpwebresponse

    Hi
    Im writing a neat little app to fetch raw text content from a website.
    However, the website im trying to get data from first sends me to a "bandwidth test site", then redirects me to the site i want data from. How can i handle this in c#?
    Code so far;

    VB Code:
    1. String url = "http://www1.nrk.no/nett-tv/bokstav/@";
    2. String content = "";
    3. HttpWebRequest request=(HttpWebRequest)WebRequest.Create(url);
    4. request.AllowAutoRedirect=true;
    5. request.MaximumAutomaticRedirections=200;
    6. HttpWebResponse request = (HttpWebResponse)myHttpWebRequest.GetResponse();
    7.  
    8. // Gets the stream associated with the response.
    9. Stream receiveStream = request.GetResponseStream();
    10. Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
    11.  
    12. StreamReader readStream = new StreamReader( receiveStream, encode );
    13. content = readStream.ReadToEnd();
    14.            
    15. textBox1.Text=content;

    This only gets the inital page...so, how to get the redirect page?
    madsun

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: Handling redirects with httpwebresponse

    The request.ResponseUri.ToString(); is "http://www1.nrk.no/nett-tv/hastighet.aspx?retururl=http://www1.nrk.no/nett-tv/bokstav/@" and that takes me back to the same inital page wich im trying to avoid

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width