Codemetric optimized httpwebrequest in C#

Posted by Omegavirus on Stack Overflow See other posts from Stack Overflow or by Omegavirus
Published on 2010-12-24T16:51:40Z Indexed on 2010/12/24 16:54 UTC
Read the original article Hit count: 417

Filed under:
|

Hello, the problem is the httpwebrequest method in my c# program. visual studio gives it a metric of 60, thats pretty lame.. so how can i program it more efficient? (:

my actual code:

public string httpRequest(string url)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";
        request.Proxy = WebRequest.DefaultWebProxy;
        request.MediaType = "HTTP/1.1";
        request.ContentType = "text/xml";
        request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12";

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader streamr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
        String sresp = streamr.ReadToEnd();
        streamr.Close();
        return sresp;
    }

thanks for helping. ;)

© Stack Overflow or respective owner

Related posts about c#

Related posts about httpwebrequest