AppMetrics.Client.HttpUtil.Request C# (CSharp) Method

Request() public static method

public static Request ( string url, string>.Dictionary args = null, string method = "GET", int timeout = DefaultTimeout, ICredentials credentials = null ) : string
url string
args string>.Dictionary
method string
timeout int
credentials ICredentials
return string
        public static string Request(string url, Dictionary<string, string> args = null, string method = "GET", 
			int timeout = DefaultTimeout, ICredentials credentials = null)
        {
            var buf = new StringBuilder();
            if (args != null)
            {
                foreach (var val in args)
                {
                    buf.AppendFormat("{0}={1}&", Uri.EscapeDataString(val.Key), Uri.EscapeDataString(val.Value));
                }
            }

            if (method == "GET" && buf.Length > 0)
            {
                if (url.Contains("?"))
                    url += "&";
                else
                    url += "?";
                url += buf;
            }

            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = method;
            request.Timeout = timeout;
            request.ReadWriteTimeout = request.Timeout;
            request.Credentials = credentials;

            if (method == "GET")
            {
                request.ContentType = "text/plain; encoding='utf-8'";
            }
            else if (method == "POST")
            {
                request.ContentType = "application/x-www-form-urlencoded; encoding='utf-8'";

                using (var stream = request.GetRequestStream())
                {
                    using (var writer = new StreamWriter(stream)) // UTF8 without BOM
                    {
                        writer.Write(buf.ToString());
                    }
                }
            }

            using (var response = request.GetResponse())
            using (var responseStream = response.GetResponseStream())
            using (var reader = new StreamReader(responseStream, Encoding.UTF8))
            {
                return reader.ReadToEnd();
            }
        }

Same methods

HttpUtil::Request ( string url, ICredentials credentials, string>.Dictionary args = null, int timeout = DefaultTimeout ) : string
HttpUtil