0
我试图根据请求发送一个XML文件,但当我试图将正在将文件加载到流中的流复制到输出流时出现错误。根据请求发送XML文件
现在它工作正常,如果我从浏览器发出请求(我使用HttpListener btw);它显示我的.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);
:“流不支持读取。”
看看这里的一些张贴答案和注释的http://stackoverflow.com/questions/230128/how-do-i-复制一个流的内容到另一个|| http://stackoverflow.com/questions/10664458/memorystream-writetostream-destinationstream-versus-stream-copytostream-desti – MethodMan 2014-11-25 14:39:03
如果你内嵌'stream'变量,你会得到'CopyStream(response.OutputStream,response.OutputStream);'这可能有助于理解为什么代码不起作用。 – 2014-11-25 15:54:37