【发布时间】:2020-01-20 04:48:40
【问题描述】:
我需要通过流数据将文件从 WEB API 下载到 windows 应用程序。
WEB API:
public HttpResponseMessage download(string fileid){
var response = new HttpResponseMessage ();
response.statuscode= HttpStatusCode.Ok;
response.Content =new StreamContent(filestream);// I have a filestream here .
return response;
此处添加内容后添加的内容配置和内容类型。 在客户端,我尝试了以下操作。
HttpResponseMessage file = httpclinet.GetAsync("url").Result();
Var stream = file.Content.ReadAsStreamAsync().Result();
using (var data = File.create(@"somepath.txt"))
{
data.seek(0,seekorigin.begin);
stream.copyto(data);
}
但我没有得到输出。我得到的是
流详细信息,例如 stream.content ,statuscode 的版本对象。就像那个文件被写了一样。
如何在这个文件中写入流数据。
【问题讨论】:
标签: c# asp.net-web-api download stream