问题
For downloading files from my server I use this method in asp.net MVC:
string fileName = "SAMSUNG.zip";
string path = @"D:\Tutorial MVC5\ContosoUniversity\ContosoUniversity\dlfile\";
string fullPath = path + fileName;
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/x-zip-compressed";
Response.WriteFile(fullPath);
Response.End();
But, what about when I want to download files from another server, for example from a "host download". How can I do that? For example my download direct link is: http://dl.test.com/file.zip
,
now user clicks a link <a href="http://test.com/1">file.zip</a>
is to download the file. Now I want to send file.zip
to the user without a user knowing where my trusted link is and where my host download is. She or he just chooses the file to download.
Thanks for help!
回答1:
are you familiar with how to use and or Set Request.Params
your url originally should look like this if you want to check the QueryString
http://dl.test.com?file_name=SAMSUNG.zip
if(Request.Params["file_name"] == "SAMSUNG.zip"
{
Uri uri = new Uri("http://dl.test.com/file.zip");
using (var wc = new WebClient())
using (var download = wc.OpenRead(uri))
using (var respStream = Response.OutputStream)
{
download.CopyTo(respStream);
}
}
来源:https://stackoverflow.com/questions/33835563/download-file-from-url-on-other-server-host-download-asp-net-mvc