public string Query(string queryString) { try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(AOPResource.LVSRequestURL); request.Method = "POST"; UTF8Encoding encoding = new UTF8Encoding(); byte[] byteArray = encoding.GetBytes(queryString); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(byteArray, 0, byteArray.Length); WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader sr = new StreamReader(responseStream); string result = sr.ReadToEnd(); requestStream.Close(); sr.Close(); responseStream.Close(); return result; } catch (WebException e) { using (WebResponse response = e.Response) { HttpWebResponse httpResponse = (HttpWebResponse)response; Console.WriteLine("Error code: {0}", httpResponse.StatusCode); using (Stream data = response.GetResponseStream()) using (var reader = new StreamReader(data)) { string text = reader.ReadToEnd(); throw new Exception(text); } } } }