2016-08-03 95 views
0

嗨大家好我试图写一个游戏修补程序,所以我正在下载一个文件,以找到我已经做了很多研究什么代码应该使用所有不同的方法结果在同一个WebClient下载文件工作不正确

  WebClient downloadClient = new WebClient(); 
      Uri url = new Uri("http://theblademasterrpg.com/Patcher/data/p.dat"); 
      downloadClient.DownloadFile(url, Application.StartupPath + "\\p2.dat"); 
      downloadClient.Dispose(); 
      FileStream file = new FileStream(Application.StartupPath + "\\p2.dat", FileMode.Open, FileAccess.Read); 

      string fileContents; 
      using (StreamReader reader1 = new StreamReader(file)) 
      { 
       fileContents = reader1.ReadToEnd(); 
      } 

文件似乎下载,但它不是纠正这种文件只有文字,它像1.0

它总是显示这个不管我做什么,甚至将其更改为HTML文件

enter image description here

我不能帮助,但认为这是值得的Web服务器相关的,所以我尝试的Apache,而不是IIS具有相同的结果

有其他人expirenced这个我宁愿下载HTTP和避免FTP

回答

0

该网站是不是去给那个容易的文件给你。您需要解析的初步反应了一下,你正在寻找这个字符串:

<frame src="http://71.82.23.25:8080/Patcher/data/p.dat" name="redir_frame" frameborder="0"> 

,然后在该src属性中的URL再次但是现在称之为DownloadString

此代码快速破解用字符串IndexOf找到该属性。

using(WebClient downloadClient = new WebClient()) 
{ 
    Uri url = new Uri("http://theblademasterrpg.com/Patcher/data/p.dat"); 
    var html= downloadClient.DownloadString(url); 
    // parse to the frame src 
    var search = "<frame src=\""; 
    var pos = html.IndexOf(search); 
    // find the end quote 
    var lastQuote = html.IndexOf("\"", pos+ search.Length); 
    // download that src 
    var frameUrl = html.Substring(pos+ search.Length, lastQuote- (pos + search.Length)); 
    var real = downloadClient.DownloadString(frameUrl); 
    // real has now the content of that file 
    real.Dump(); // LinQPad 
} 

请注意,网站更改他们的html标记,您需要相应地适应此代码。

+0

谢谢你我现在明白了,因为我自己托管自己并掩盖了我的网址,所以它不是正确的^。^谢谢你的回复 – quatre432