Search code examples
c#httpwebrequest

Reducing HttpWebRequest time or reading website line by line backwards


Orginal Question

I am writing a remote connection for a game server. It needs to read the log files to determine what is happening in the server. I have written a method to read the log file. This currently takes 7720ms to complete.

    private string getlog()
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(logFileLocation);
        webRequest.UserAgent = ".NET Framework Test Client";
        webRequest.Accept = "text/html";
        HttpWebResponse httpResponse = (HttpWebResponse)webRequest.GetResponse();
        string responseData;
        using (StreamReader responseReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            responseData = responseReader.ReadToEnd();
        }
        return responseData;
    }

I am trying to reduce the time that this method runs. Now the file it is getting is about 7000 line long starting from the oldest information. And I won't need the old information at all, so I'm reading it for no reason. Is there a way to read the file line by line backwards. Or are there ways I can speed up this method?


EDIT

Code is now

    private string getlog()
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(logFileLocation);
        webRequest.UserAgent = ".NET Framework Test Client";
        webRequest.Accept = "text/html";
        webRequest.Proxy = null; //Thanks to tsandy
        HttpWebResponse httpResponse = (HttpWebResponse)webRequest.GetResponse();
        string responseData;
        using (StreamReader responseReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            responseData = responseReader.ReadToEnd();
        }
        return responseData;
    }

Solution

  • Proxy auto-detect is slow- try webRequest.Proxy = null;