我想知道如何或是否可以使用 C# 读取 pastebin 的各个行。我想阅读http://pastebin.com/raw.php?i=fTgJF857的行并检查每行中的文本是否与另一个字符串匹配。这可能吗/我该怎么做?
我的目标是将用户 ID 与 ID 列表进行比较。有点像白名单。像这样的东西:
if(linefrompastebin == useridstring)
{
_isAllowed = true
}
我想知道如何或是否可以使用 C# 读取 pastebin 的各个行。我想阅读http://pastebin.com/raw.php?i=fTgJF857的行并检查每行中的文本是否与另一个字符串匹配。这可能吗/我该怎么做?
我的目标是将用户 ID 与 ID 列表进行比较。有点像白名单。像这样的东西:
if(linefrompastebin == useridstring)
{
_isAllowed = true
}
HttpWebRequest
(或WebClient
或HttpClient
取决于当前的月相)从 PasteBin 请求文本GetResponseStream
捕获流StreamReader
(String.Split
代码从 中读取 HTML 行 http://pastebin.com/raw.ph ?i=fTgJF857
,将数据存储在字符串数组中,并逐行检查每行中的文本是否与引用字符串匹配。
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();
}
}
}