【发布时间】:2014-11-25 14:34:00
【问题描述】:
我正在尝试根据请求发送 XML 文件,但是当我尝试将要加载文件的流复制到输出流时出现错误。
现在如果我从浏览器发出请求(我使用 HttpListener 顺便说一句),它工作正常;它向我展示了我的 .xml 就好了。但我也希望能够在我提出请求时下载 .xml。
有什么建议吗?
string xString = @"C:\Src\Capabilities.xml";
XDocument capabilities = XDocument.Load(xString);
Stream stream = response.OutputStream;
response.ContentType = "text/xml";
capabilities.Save(stream);
CopyStream(stream, response.OutputStream);
stream.Close();
public static void CopyStream(Stream input, Stream output)
{
input.CopyTo(output);
}
我得到的错误是input.CopyTo(output);:“流不支持阅读。”
【问题讨论】:
-
在这里查看一些已发布的答案和 cmets stackoverflow.com/questions/230128/… || stackoverflow.com/questions/10664458/…
-
如果你内联
stream变量,你会得到CopyStream(response.OutputStream, response.OutputStream);这可能有助于理解为什么代码不起作用。