Client
WebClient client = new WebClient();
byte[] file = client.DownloadData("http://domain.com/default.aspx");
File.WriteAllBytes("helloworld.txt", file);
Server
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (MemoryStream memory = new MemoryStream())
using (StreamWriter writer = new StreamWriter(memory))
{
writer.WriteLine("hello, world");
writer.Flush();
Response.BinaryWrite(memory.ToArray());
}
Response.AddHeader("Content-Disposition", "Attachment; filename=helloworld.txt");
Response.AddHeader("Content-Type", "application/octet-stream");
Response.End();
}
}
, , ! , , , WebClient.DownloadData() . , . , .
:
, , .
- HTTP- . , . - HTTP-GET , - HTML. , , Content-Type Text/HTML. , , MIME, Content-Type text/plain, , . /XML XML .. , MIME .
" " , Content-Disposition: Attachment. , .
WebClient/HttpWebRequest, , , , , MIME/HTTP-, . Content-Disposition ( ) Open Save.