CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2011
    Posts
    17

    HttpWebRequest/Response Exception

    Hi, Im trying to build an app that retrieves real-time fx quotes.

    Im getting an exception "cannot access a disposed object" when I try to make a 2nd call to GetResponse() even though I am disposing off it through using statements (I've tried to call Close() manually; this did not solve problem).

    Code:
    static void Main(string[] args)
            {
                string sessionID = "xxxxxx";
                
                HttpWebRequest rateRequest = HttpWebRequest.Create(string.Format(@"http://webrates.truefx.com/rates/connect.html?id={0}", sessionID)) as HttpWebRequest;
                HttpWebResponse rateResponse;
        
                    while (true)
                    {
                        using (rateResponse = rateRequest.GetResponse() as HttpWebResponse)
                        {
                            if (rateResponse != null)
                            {
                                 using (StreamReader rateReader = new StreamReader(rateResponse.GetResponseStream()) )
                                 {
                                     Console.WriteLine(rateReader.ReadToEnd());
                                 }
                            }
                        }
                    }
                }

    Would really appreciate some help!
    Last edited by techtalk7; January 8th, 2012 at 05:56 PM.

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

Featured