【问题标题】:Getting link from pastebin and downloading from link从 pastebin 获取链接并从链接下载
【发布时间】:2016-09-16 18:29:07
【问题描述】:

我正在尝试从 pastebin 获取链接。链接是原始粘贴中唯一的文本。然后我想从pastebin中的链接下载一个文件。

WebRequest request = WebRequest.Create("http://pastebin.com/raw/Dtdf2qMp");  

WebResponse response = request.GetResponse();     

System.IO.StreamReader reader = new  

System.IO.StreamReader(response.GetResponseStream());

Console.WriteLine(reader.ReadToEnd());

WebClient client = new WebClient();

client.DownloadFile (Link gotten from pastebin here, "c:\\File");

System.Threading.Thread.Sleep(5000);

【问题讨论】:

    标签: c# download pastebin


    【解决方案1】:

    不应将读取的文本转储到控制台输出,而应将其分配给变量。

    var pastebinOutput = reader.ReadToEnd();
    

    然后将其作为 DownloadFile 方法的链接传递。如果您想验证它实际上是您从原始 pastebin 获得的 URL,您可以查看 System.Uri 的 TryCreate 方法。

    【讨论】:

      【解决方案2】:

      我有一个解决方案 - 假设你在原始 pastebin 链接中有你的链接(我的是一个 .txt 文件说“它有效”)我建议你复制并粘贴下面的代码 - 如果你得到一个文件说'它工作' 然后你可以更改 pastebin 链接和文件名。如果您不想打开文件,请删除 Process.Start - 如果您想更改延迟,只需更改数字(以毫秒为单位)此外,您可以将格式从 .txt 更改为 .exe 或任何文件(或者您可以将其删除,使其成为下载链接中的默认名称):

      WebRequest request = WebRequest.Create("https://pastebin.com/raw/QAWufg1z");
      WebResponse response = request.GetResponse();
      
      System.IO.StreamReader reader = new
      
      System.IO.StreamReader(response.GetResponseStream());
      
      var pastebinOutput = reader.ReadToEnd();
      
      WebClient client = new WebClient();
      
      client.DownloadFile(pastebinOutput, @".\downloaded.txt");
      MessageBox.Show("File should open automatically in the next minute. Please wait...");
      await Task.Delay(3000); //3000 = 3 seconds
      
      Process.Start(@".\downloaded.txt");
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多