using System.IO; using System.Net; namespace Muchinfo.MTPClient.Infrastructure.Utilities { public enum RequestMethod { Get, Post } public class HttpUtility { public static string HttpGet(string url) { var request = CreateGetRequest(url); var response = (HttpWebResponse)request.GetResponse(); var stream = response.GetResponseStream(); if (stream == null) return string.Empty; var streamReader = new StreamReader(stream); string responseContent = streamReader.ReadToEnd(); response.Close(); streamReader.Close(); return responseContent; } private static HttpWebRequest CreateGetRequest(string url) { url = url.Trim(); if (!url.Contains("://")) url = "http://" + url; var request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; request.Method = "GET"; request.Timeout = 20000; return request; } } }