Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4581882
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:59:33+00:00 2026-05-21T20:59:33+00:00

I am using HttpWebResponse.GetResponseStream to access an internet radio stream, and want to read

  • 0

I am using HttpWebResponse.GetResponseStream to access an internet radio stream, and want to read some data from the response stream, and then disconnect. However, I always hang indefinitely on the Dispose of the stream. The unit test below will display “Cleaning up networkStream…”, but never get to “Finished”. Why is this? And should I fix it by just not bothering to Dispose of my networkStream?

[Test]
public void CanStreamMP3Radio()
{
    string url = @"http://radio.reaper.fm/stream/";
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

    int total = 0;
    byte[] buffer = new byte[1024];

    using(var networkStream = resp.GetResponseStream())
    {
        do
        {
            int bytesRead = networkStream.Read(buffer, 0, buffer.Length);
            Console.WriteLine("{0} bytesRead", bytesRead);
            total += bytesRead;
        } while (total < 16384);
        Console.WriteLine("Cleaning up networkStream...");
    }
    Console.WriteLine("Finished");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:59:34+00:00Added an answer on May 21, 2026 at 8:59 pm

    EDIT: just found a solution… call req.Abort() before the end of the using block. Not very elegant, but it works… So the code becomes:

    [Test]
    public void CanStreamMP3Radio()
    {
        string url = @"http://radio.reaper.fm/stream/";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
        {
            int total = 0;
            byte[] buffer = new byte[1024];
    
            var networkStream = resp.GetResponseStream();
            do
            {
                int bytesRead = networkStream.Read(buffer, 0, buffer.Length);
                Console.WriteLine("{0} bytesRead", bytesRead);
                total += bytesRead;
            } while (total < 16384);
            Console.WriteLine("Cleaning up HttpWebResponse...");
            req.Abort();
        }
        Console.WriteLine("Finished");
    }
    

    Try disposing the HttpWebResponse instead:

    [Test]
    public void CanStreamMP3Radio()
    {
        string url = @"http://radio.reaper.fm/stream/";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
        {
            int total = 0;
            byte[] buffer = new byte[1024];
    
            var networkStream = resp.GetResponseStream();
            do
            {
                int bytesRead = networkStream.Read(buffer, 0, buffer.Length);
                Console.WriteLine("{0} bytesRead", bytesRead);
                total += bytesRead;
            } while (total < 16384);
            Console.WriteLine("Cleaning up HttpWebResponse...");
        }
        Console.WriteLine("Finished");
    }
    

    It should dispose the NetworkStream as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the WebClient class to post some data to a web form.
Basically, I'm getting some data from a WebService, and in the ResponseCallback I'm trying
I am trying to get some data from a web server. When I go
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Having nicked some code from msdn I'm miffed that it doesn't work exactly as
I need to get json data from an external domain. I used WebRequest to
I use the following method to retrieve something from a webservice using a HTTPWebRequest:
Hey trying to read stream into image control can any one help also I
I need your help in finding better way in downloading a url using HttpWebResponse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.