2

I am getting a shoutcast stream using a HTTPRequest on Windows Phone. When I get the result, the headers are all empty. The response headers are in the stream (the stream position is before the response headers) so I can parse the headers out of the stream however this is causing some issues when trying to keep track of the number of bytes in order to get metadata.

enter image description here

When I run the same code in a Windows Desktop application. The response has the headers and the stream starts at the response body (mp3 bytes).

enter image description here

The only difference between the code is that the desktop app has the following in the app config.

<system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
</system.net>

This is a media stream so the response doesn't have a size. The connection and stream will remain open until manually closed. Is it possible to get the response headers on Windows Phone like I do in the Windows Desktop app? Are there alternatives (such a HTTPClient) that will allow me to specify request headers, get the response headers, and get the response stream?

3
  • 1
    Yes, System.Net.Http.HttpClient should let you do that.
    – kiewic
    Dec 30, 2013 at 17:51
  • I tried using HTTP client: var client = new HttpClient(); var requestMessage = new HttpRequestMessage(HttpMethod.Get, "sc64.blast.fast-serv.com:80"); requestMessage.Headers.Add("User-Agent", "WinampMPEG/5.0"); requestMessage.Headers.Add("Icy-MetaData", "1"); HttpResponseMessage response = await client.SendAsync(requestMessage); however, the code hangs on SendAsync. I am assuming this is because the responce stream length never ends. Ideas? Dec 31, 2013 at 17:26
  • 1
    There are some problems with your code as you'd have to use the SendAsync overload with the HttpCompletionOption.ResponseHeadersRead enum and then call response.Content.ReadStreamAsync(). However, the problem is that HttpClient will not support parsing unsafe headers, so you'll still find your header count is 0. See this MSDN forum thread for reference.
    – lsuarez
    Dec 31, 2013 at 18:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.