日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# 破解防盗链

發布時間:2023/12/18 C# 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# 破解防盗链 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

C#版本 java類似 流用法略不同

private void WriteFile(byte[] info, string fullpath)
??????? {
??????????? FileStream fs = null;
??????????? BinaryWriter w = null;
??????????? try
??????????? {
??????????????? //string name = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.ffffff") + ".html";
??????????????? //string path = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "MN\\" + name);
??????????????? fs = new FileStream(fullpath, FileMode.CreateNew, FileAccess.ReadWrite);
??????????????? // 轉換為字節 寫入數據 ( 可寫入中文 )
??????????????? //Byte[] info = Encoding.GetEncoding("GB2312").GetBytes(content);
??????????????? // 字節數組 , 字節偏移量 , 最多寫入的字節數
??????????????? w = new BinaryWriter(fs);
??????????????? // 設置要寫入的偏移量 ?
??????????????? fs.Position = fs.Length;
??????????????? fs.Write(info, 0, info.Length);
??????????? }
??????????? finally
??????????? {
??????????????? if (w != null)
??????????????????? w.Close();
??????????????? if (fs != null)
??????????????????? fs.Close();
??????????? }
??????? }

?private void imgService(HttpContext context)
??????? {
??????????? HttpRequest request = context.Request;
??????????? HttpResponse response = context.Response;
??????????? string url = request.QueryString["url"];
??????????? string fileName = url.GetHashCode().ToString()+".gif";
??????????? string ipaddress = System.Configuration.ConfigurationManager.AppSettings["ipaddress"];
??????????? //string path = System.Configuration.ConfigurationManager.AppSettings["path"];
??????????? string savePath = URLUtil.getDomainName(url).Replace(".", "_");//保存的文件夾
??????????? //string fileName = url.Substring(url.LastIndexOf("/")+1);//保存的文件名
??????????? string savename = context.Server.MapPath("imgs") + "\\" + savePath + "\\" + fileName;
??????????? if (!File.Exists(savename))
??????????? {
??????????????? HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
??????????????? webrequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/QVOD, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
??????????????? webrequest.Headers.Add("Accept-Encoding", "gzip, deflate");
??????????????? webrequest.Headers.Add("Accept-Language", "zh-cn");
??????????????? webrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; MS-RTC LM 8; Alexa Toolbar)";
??????????????? webrequest.Headers.Add("UA-CPU", "x86");
??????????????? webrequest.KeepAlive = true;
??????????????? HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
???????????????

??????????????? if (webresponse.StatusCode == HttpStatusCode.OK)
??????????????? {
?????????????????? // System.Drawing.Image image = System.Drawing.Image.FromStream(webresponse.GetResponseStream());
??????????????????? Stream st = webresponse.GetResponseStream();
??????????????????? BinaryReader br = new BinaryReader(st);
??????????????????? byte[] poto = br.ReadBytes(4096+(int)webresponse.ContentLength);
??????????????????? if (!System.IO.Directory.Exists(context.Server.MapPath("imgs") + "\\" + savePath))
??????????????????? {
??????????????????????? System.IO.Directory.CreateDirectory(context.Server.MapPath("imgs") + "\\" + savePath);
??????????????????? }

??????????????????? WriteFile(poto, savename);
???????????????????

??????????????????? /*string ct=webresponse.ContentType.ToLower();
??????????????????? if (ct.IndexOf("gif") > 0)
??????????????????? {
??????????????????????? //image.Save(savename);
??????????????????? }
??????????????????? else
??????????????????? {
?????????????????????? //image.Save(savename, System.Drawing.Imaging.ImageFormat.Gif);//保存路徑
??????????????????? }
??????????????????? //image.Dispose();//釋放資源 */
???????????????
??????????????? }
??????????? }
??????????? response.Redirect(ipaddress +savePath+"/"+ fileName);


??????? }

轉載于:https://www.cnblogs.com/MakethingsEasy/archive/2012/08/03/2622165.html

總結

以上是生活随笔為你收集整理的C# 破解防盗链的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。