-1
我搜索了網絡,但無法找到任何方式獲得進展,而下載文件與HttpWebRequest。這個班級是否支持進步?任何鏈接,教程,提示將不勝感激。HttpWebRequest的下載文件和進度條
謝謝。
P.S.這裏是代碼...
private static Task<HttpResponse> MakeAsyncRequest(string requestString)
{
var request = (HttpWebRequest)WebRequest.Create(requestString);
Task<WebResponse> requestTask = Task.Factory.FromAsync(
request.BeginGetResponse,
asyncResult => request.EndGetResponse(asyncResult),
null);
return requestTask.ContinueWith(t => ReadStreamFromResponce(t.Result));
}
private static HttpResponse ReadStreamFromResponce(WebResponse result)
{
var responseobject = new HttpResponse();
var response = (HttpWebResponse)result;
responseobject.StatusCode = (short)response.StatusCode;
if (!IsSuccess(responseobject.StatusCode))
return responseobject;
using (var responseStream = response.GetResponseStream())
using (var ms = new MemoryStream())
{
responseStream.CopyTo(ms);
responseobject.SetResponse(ms.ToArray());
return responseobject;
}
}
謝謝,不幸的是我使用PCL(可移植類庫)項目,我們沒有Begin ****方法。你知道是否有可能在PCL中做類似的事情?謝謝 – Davita 2013-05-07 12:07:41