2011-11-10 11 views
0

私はテスト用のコンソールアプリケーションで何かをしようとしています(WebアプリケーションのHttpHandlerのコードに基づいています)。 たのHttpContextがそれに合格した私のHttpHandlerのために働く以下のようなものを考えるとHttpHandlerがHttpcontext.Response.OutputStream.Writeでできることをストリームするために、System.Net.WebClientをコンソールアプリケーションで使用できますか?

:私はそれの一部を持っている

context.Response.AppendHeader("Content-Length", docContent.Length.ToString()); 
context.Response.AppendHeader("content-disposition", "attachment; filename=\"" + fileName + "\""); 
context.Response.ContentType = MIMEType.MimeType(fileType); 
context.Response.OutputStream.Write(docContent, 0, docContent.Length); 
context.Response.OutputStream.Flush(); 

は、私は思うし、私は動けなくなる:

WebClient client = new WebClient(); 

client.Headers.Add("Content-Length", docContent.Length.ToString()); 
client.Headers.Add("content-disposition", "attachment; filename=\"" + fileName + "\""); 
string ContentType = MIMEType.MimeType(fileType); 
// ?? 
// how to build the response as an output stream from my byte array which has the data ? 

答えて

1

MemoryStream(byte[])byte[]からStreamを作成できます。

しかし、問題はWebClientは、HTTP 要求のみを発行するように設計されています。添付ファイルをダウンロードしてサーバーをテストするのが目的ならば、別のヘッダーが必要になります。

実際にファイルをダウンロードしようとしている場合は、WebClient.DownloadFile

関連する問題