c# 从一个服务器 访问另外一个服务器上的文件

时间:2019-02-18 13:39:38   收藏:0   阅读:511

页面调用 

function fnOpen(path) {
window.open("~/FileHelp.ashx? url=");
//window.open(url);
}

 

后台一般处理程序  

技术分享图片

var myWebClient = new WebClient();
var url = context.Request["url"];
var cread = new NetworkCredential("账号", "密码", "domain");
myWebClient.Credentials = cread;
var fs = new FileStream(@"", FileMode.Open, FileAccess.Read);

byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
context.Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("sf.jpg", System.Text.Encoding.UTF8));
context.Response.BinaryWrite(bytes);
context.Response.Flush();

 

 

 

原文:https://www.cnblogs.com/jixinyu12345/p/10394777.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!