我正在制作适用于Windows 8.1的在线广播应用,并希望使用新的shoutcast
与Windows.Web.Http API
服务器进行通信(以便发送自定义HTTP标头以从实时媒体流中获取元数据)
响应头是空的,我需要在开始读取流数据之前读取内容头。
这是我尝试使用的代码:
Uri uri = new Uri(Url);
var baseFilter = new HttpBaseProtocolFilter();
ShoutcastHttpFilter filter = new ShoutcastHttpFilter(baseFilter);
var HClient = new HttpClient(filter);
HttpResponseMessage response = await HClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);
Task streaming = null;
Stream stream = null;
stream = response.Content.ReadAsInputStreamAsync().GetResults().AsStreamForRead();
string str = response.Content.Headers["Icy-MetaInt"];
当我运行/调试代码时,内容显示为"无缓冲"并且没有标题。 如何获取内容标题和流?
这是我在ShoutcastHttpFilter中使用的代码:
request.Headers.Clear();
request.Headers.Add("Icy-MetaData", "1");
request.Headers["User-Agent"] = "VLC media player";
request.Headers["Connection"] = "Close";
HttpResponseMessage response = await innerFilter.SendRequestAsync(request).AsTask(cancellationToken, progress);
cancellationToken.ThrowIfCancellationRequested();
return response;
答案 0 :(得分:0)
如果标题名称不以Content-*
开头,则标题必须位于响应标题中。
这样做:
Uri uri = new Uri("http://example.com");
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(
uri,
HttpCompletionOption.ResponseHeadersRead);
string value = response.Headers["Icy-MetaInt"];