I'm trying to get the contents of a hosted .txt file on a website and compare it to a string or "key". Both strings read as the same however when compared against each other in an if statement to see if they match, they apparently do not.
For example, the contents of http://1.2.3.4/test.txt is 'hello'
using System;
using System.IO;
using System.Net;
namespace TestProgram
{
public class Program
{
static void Main(string[] args)
{
string key = "hello";
WebRequest request = WebRequest.Create("http://1.2.3.4/test.txt");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
html = sr.ReadToEnd();
}
if (html == key)
{
Console.WriteLine("True");
Console.ReadKey();
}
}
}
}
I've tried html.Equals(key)
and that doesn't work either. I've used WebClient
as well and get the same result.