【问题标题】:C# Reading a raw pastebin by linesC#逐行读取原始的pastebin
【发布时间】:2015-12-14 00:25:54
【问题描述】:

我想知道如何或是否可以使用 C# 读取 pastebin 的各个行。我想阅读http://pastebin.com/raw.php?i=fTgJF857 的行并检查每行中的文本是否与另一个字符串匹配。这可能吗/我该怎么做?

我的目标是将用户 ID 与 ID 列表进行比较。有点像白名单。像这样的:

if(linefrompastebin == useridstring) { _isAllowed = true }

【问题讨论】:

    标签: c# pastebin


    【解决方案1】:
    1. 使用HttpWebRequest(或WebClientHttpClient,取决于当前的月相)从PasteBin请求文本
    2. 捕获流 (GetResponseStream) 并使用 StreamReader 逐个字符地读取它,或者使用客户端的逻辑将其保存到一个字符串中,然后恶意调用 String.Split

    【讨论】:

    • 非常感谢!你知道我如何将字符串与另一个字符串(如:if(strings == "987654321"))进行比较,是否可以让它只运行一次?
    【解决方案2】:

    代码从 http://pastebin.com/raw.ph ?i=fTgJF857 读取 HTML 行,将数据存储在字符串数组中,并逐行检查每行中的文本是否与引用字符串匹配。

    using  System;
    using  System.Net;
    using  System.IO;
    
    namespace ConsoleApplication5{
        class Program    {
            static void Main(string[] args){                
                string[] linefrompastebin = new string[100];
                string useridstring = "76561198079483032";
                int i = 0;
                int maxLines = 0;
                bool _isAllowed = false;
    
                var url = "http://pastebin.com/raw/fTgJF857";
                var client = new WebClient();
    
                Console.WriteLine("Reading HTML at :  http://pastebin.com/raw/fTgJF857 \n\n");
    
                using (var stream = client.OpenRead(url))
                using (var reader = new StreamReader(stream)) {
                linefrompastebin[0] = "";
    
                //Store lines from HTML into string
                while ((linefrompastebin[i] = reader.ReadLine()) != null){
                    i++;
                }
                maxLines = i;
                }
    
                //do some line processing - compare user with whitelist
                for (i = 0; i < maxLines;i++ ){
                    Console.WriteLine(linefrompastebin[i]);
    
                    if(linefrompastebin[i] == useridstring){
                        _isAllowed = true;
                        Console.WriteLine("\n");
                        Console.WriteLine("_isAllowed = true on -> "+ linefrompastebin[i]+ ". user Exists in database");
                     }
    
                }
    
                linefrompastebin = null;
                Console.WriteLine("\n\n");
                Console.ReadLine();
    
    
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-08-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 2014-06-21
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      相关资源
      最近更新 更多