我不断收到类似字符串的错误,它说它不能将'byte []'转换为字符串。当我将其作为var时,它说的是同一件事,但结果是我对Results.txt旁边的数据有错误。
if (Lock.Contains("Mode: Data Grabber"))
{
Console.WriteLine("Loading Data Grabber 2.0! Mode = Data Grabber!\n");
Console.WriteLine("Enter the websites url!\n");
Console.WriteLine("(\n) " + "(\n)");
if (Option == Option)
{
WebClient wc = new WebClient();
string data = wc.DownloadData(Option);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Downloading data from " + data);
Thread.Sleep(3000);
Console.WriteLine("\n");
if (!File.Exists(Directory.GetCurrentDirectory() + @"/Results.txt"))
{
File.Create(Directory.GetCurrentDirectory() + @"/Results.txt");
}
File.WriteAllText(Directory.GetCurrentDirectory() + @"/Results.txt", data);
Console.WriteLine("All data has been sent to the path");
}
}
答案 0 :(得分:0)
如果您有string
,即byte[]
,则尝试写data
string data = wc.DownloadData(Option);
WebClient.DownloadData返回一个byte[]
public byte[] DownloadData (string address);
尝试:
string data = wc.DownloadString (address);
答案 1 :(得分:0)
您在这里:
将此代码string data = wc.DownloadData(Option);
替换为System.Text.Encoding.UTF8.GetString(wc.DownloadData(Option))
前提是相应文本的编码为UTF-8。
希望这会有所帮助。
答案 2 :(得分:0)
您应该使用WebClient的“ DownloadString”方法来获取字符串:
string data = wc.DownloadString (Option);
现在内容将是一个字符串。