HttpWebRequest的初始化 - 响应从未收到 [英] HttpWebRequest initializing - response never received
问题描述
我目前工作中的应用程序为Windows Phone 7应该检索Shoutcast一样流的实现(通过<一个启发href="http://stackoverflow.com/questions/3734843/httpwebrequest-for-shoutcast-on-windows-phone7/3743113#3743113">this问题)。流位置被重新由IP地址和端口psented $ P $。
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.
下面是一个Shoutcast一样流URL的一个例子: http://78.159.104.183:80
Here is an example of a SHOUTcast stream URL: http://78.159.104.183:80
我试图做一个的HttpWebRequest 得到的流中的数据:
I am trying to make a HttpWebRequest to get the data from the stream:
HttpWebRequest的要求=(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看起来是这样的:
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.
我注意到一件有趣的事情 - Shoutcast一样实现了由当用户试图浏览到流URL技术,服务器检测用户代理,如果它是一个Web浏览器,它只会显示一个HTML页面,而不是传球应用程序/八位字节流的内容。
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.
您还可以直接接收流,如果你使用一个斜杠和分号流URL的末尾:的 http://78.159.104.183:80/;
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/;
不过,在我的应用程序,我无法获得响应 - 回调似乎永远无法达到。我试着通过直接将它传递给HttpWebRequest的伪造的用户代理:
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";
这适用于简单的流URL(没有分号结尾),以获得HTML内容,但我不能得到二进制流。
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?
推荐答案
我不知道这是否会为你工作,但我有同样的问题,
I have no idea if this would work for you but I had the same problem,
和明确设置
request.AllowReadStreamBuffering = FALSE; request.Method =GET;
request.AllowReadStreamBuffering = false; request.Method = "GET";
好像是什么原因让我的回调火...
seemed to whatever reason get my callback to fire...
我不知道为什么。
这篇关于HttpWebRequest的初始化 - 响应从未收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!