我需要将代理与 HtmlAgilityPack 一起使用。我给出了我的应用程序的链接RefURL。之后我希望应用程序从代理地址获取 url。例如“101.109.44.157:8080”
我搜索并发现了这个:
WebClient wc = new WebClient();
wc.Proxy = new WebProxy(host,port);
var page = wc.DownloadString(url);
Run Code Online (Sandbox Code Playgroud)
并像这样使用它。
RefURL = new Uri(refLink.Text);
WebClient wc = new WebClient();
wc.Proxy = new WebProxy("101.109.44.157:8080");
var page = wc.DownloadString(RefURL);
RefURL.ToString();
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load(RefURL.ToString());
Run Code Online (Sandbox Code Playgroud)
但它不起作用!
是否有任何方法可以获得(实际猜测!)扩展文件?在我的程序中,我得到一个文件,应用程序分析它以理解它是ZIP还是MOV.
我发现了这个,但它不支持MOV和ZIP.
更新:
通过创建包含文件签名的前8位的文本文件.以下代码,我可以确定每个没有扩展名的文件. 这个页面可能是一个很好的参考.
string rootPath = $"{name}";
using (FileStream fsSource = new FileStream(rootPath, FileMode.Open, FileAccess.Read))
{
byte[] fileBytes = new byte[8]; // the number of bytes you want to read
fsSource.Read(fileBytes, 0, 8);
/*
zip = 50-4B-03-04-0A-00-00-00
mov = 00-00-00-20-66-74-79-70
html = 3C-21-64-6F-63-74-79-70
rar 1 = 52-61-72-21-1A-07
rar 5 = 52-61-72-21-1A-07
*/
string filestring = BitConverter.ToString(fileBytes);
// string filestring = Encoding.UTF8.GetString(fileBytes);
File.WriteAllText($"{DownloadPath}\\filestring.txt", filestring);
}
Run Code Online (Sandbox Code Playgroud)