ASP MVC WebClient字节数组传输

时间:2015-12-21 11:52:19

标签: c# asp.net-mvc webclient

我有webapi应用程序,从其他资源下载文件

public byte[] DownloadDocumentContent(int id)
{
    WebClient client = new WebClient();
    client.UseDefaultCredentials = true;
    var siteUrl = System.Configuration.ConfigurationManager.AppSettings["SiteUrl"];
    return client.DownloadData(siteUrl);
}

然后我在主机MVC应用程序中接收数据,如此

public byte[] DownloadDocumentContent()
{
    WebClient client = new WebClient();
    client.UseDefaultCredentials = true; 
    return client.DownloadData(webapiURL); 
}

并将其作为文件发送给用户

public ActionResult DownloadDocument(string token)
{
    //...
    byte[] result = DownloadDocumentContent(readRequest.Document.Id);
    return File(result, ContentType, string.Format("{0}.{1}", FileName, FileExtension));
}

问题是用户收到包含无效内容的文件。 我在发送api应用程序之前检查了第一个字节 - 它是“80” 在MVC应用程序中收到后,它是“34”。我做错了什么?

0 个答案:

没有答案