【发布时间】:2015-11-12 10:24:38
【问题描述】:
我有这种方法可以在 Windows 8 项目中下载文件
try{
byte[] data;
...
Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient();
client.DefaultRequestHeaders.TryAppendWithoutValidation(
"Authorization",
"Bearer " + App.Current.Resources["token"] as string);
Uri uri = new Uri(Constants.baseAddress + "meeting/points/attachments/download?meetingId=" + meetingId + "&pointId=" + pointId + "&attachmentId=" + attachmentId);
Windows.Web.Http.HttpResponseMessage response = await client.GetAsync(uri, Windows.Web.Http.HttpCompletionOption.ResponseHeadersRead);
IInputStream inputStream = await response.Content.ReadAsInputStreamAsync();
ulong totalBytesRead = 0;
while (true)
{
// Read from the web.
IBuffer buffer = new Windows.Storage.Streams.Buffer(1024);
buffer = await inputStream.ReadAsync(
buffer,
buffer.Capacity,
InputStreamOptions.None);
if (buffer.Length == 0)
{
// There is nothing else to read.
break;
}
// Report progress.
totalBytesRead += buffer.Length;
System.Diagnostics.Debug.WriteLine("Bytes read: {0}", totalBytesRead);
// Write to file.
}
inputStream.Dispose();
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
我想将我在缓冲区中获得的字节附加到数据变量中,以便最后我将所有字节都保存在数据中
我该怎么做?
【问题讨论】:
标签: c# windows-runtime windows-store-apps