I am currently working on an implementation of an application for Windows Phone 7 that should retrieve the SHOUTcast stream (inspired by this question). The stream location is represented by an IP address and a port.
Here is an example of a SHOUTcast stream URL: http://78.159.104.183:80
I am trying to make a HttpWebRequest to get the data from the stream:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://78.159.104.183:80")
;
Once the request is initialized, I am trying to get a response via an asynchronous callback:
request.BeginGetResponse(new AsyncCallback(GetShoutAsync), request);
GetShoutAsync looks like this:
void GetShoutAsync(IAsyncResult res)
{
HttpWebRequest request = (HttpWebRequest)res.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(res);
}
When I build the project and run it, it gets to the point where the request is initialized, but the callback is never called.
I noticed an interesting thing - SHOUTcast implements a technique by which when the user tries to navigate to the stream URL, the server detects the user agent and if it is a web browser, it will simply show a HTML page instead of passing application/octet-stream content.
You can still receive the stream directly if you use a slash and semicolon at the end of the stream URL: http://78.159.104.183:80/;
However, in my application, I cannot get the response - the callback seems to never be reached. I tried faking the user agent by passing it directly to the HttpWebRequest:
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Mozilla/5.0 (X11; U; Linux i686; it-IT; rv:1.9.0.2) Gecko/2008092313 Ubuntu/9.25 (jaunty) Firefox/3.8";
This works for the simple stream URL (without the semicolon at the end) to get the HTML contents, but I cannot get the binary stream.
Anyone ever encountered something like this or knows what's causing it?