public static T GetResponse <T>(this Uri uri, string domainKey, string domainPassword) where T : class { var request = (HttpWebRequest)HttpWebRequest.Create(uri.OriginalString); string encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", domainKey, domainPassword))); request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", encoded); try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { if (response.StatusCode != HttpStatusCode.OK) { throw ExceptionMapper.GetException(response.StatusCode); } using (var stream = new StreamReader(response.GetResponseStream())) { string fullResponse = stream.ReadToEnd(); if (CloudSponge.Format.Equals("json", StringComparison.OrdinalIgnoreCase)) { return(JsonConvert.DeserializeObject <T>(fullResponse)); } else { return(ParseXml <T>(fullResponse)); } } } } catch (Exception ex) { throw ExceptionMapper.GetException(ex.Message); } }