public static string RequestUrl(string url, HttpRequestMode requestMode, string postParams) { string responseString = string.Empty; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = requestMode.ToString(); if (requestMode == HttpRequestMode.Post) { request.ContentType = "application/x-www-form-urlencoded"; if (!string.IsNullOrEmpty(postParams)) { byte[] btBodys = Encoding.UTF8.GetBytes(postParams); request.ContentLength = btBodys.Length; request.GetRequestStream().Write(btBodys, 0, btBodys.Length); } } WebResponse response = request.GetResponse(); if (response != null) { using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { responseString = sr.ReadToEnd(); } } response.Close(); } return(responseString); }
static Configuration() { CommandRequestMode = HttpRequestMode.Async; }