我有一个重定向到视频(.3gp)的页面。问题(据我所知)是在从原始页面开始请求之后,我得到了很晚的回复。我想这是因为Web请求等待数据下载。这是我的代码:
System.Uri targetUri = new System.Uri(TextBlockTargetUri.Text);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
request.AllowReadStreamBuffering = true;
request.AllowAutoRedirect = true;
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
private void ReadWebRequestCallback(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
string stuff2 = myResponse.ResponseUri.AbsoluteUri;
Dispatcher.BeginInvoke(() => TextBlockResults.Text = stuff2);
}
myResponse.Close();
}
我只需要网址,因为我使用的播放器有一个流媒体方法,所以我不应该等待整个视频下载。我怎样才能获得重定向网址而不是等待视频?
答案 0 :(得分:2)
您可以使用HEAD
http方法,只需执行:
request.Method = "HEAD";
此方法要求服务器仅返回标题