public async Task <NeoResponse> SendGetRequestAsync(Uri uri) { var webRequest = (HttpWebRequest)WebRequest.CreateHttp(uri); var response = new NeoResponse(); using (var webResponse = (HttpWebResponse)(await webRequest.GetResponseAsync())) { response.ResponseCode = (int)webResponse.StatusCode; if (IsSuccess(response)) { SetHeaders(response, webResponse); using (var responseStream = webResponse.GetResponseStream()) { using (var reader = new StreamReader(responseStream)) { response.ResponseText = await reader.ReadToEndAsync(); } } } } return(response); }
public async Task <NeoResponse> SendGetRequestAsync(Uri uri) { var response = new NeoResponse(); var responseMessage = await client.GetAsync(uri); responseMessage.EnsureSuccessStatusCode(); response.RateLimitTotal = int.Parse(responseMessage.Headers.GetValues(RateLimitHeader).First()); response.RateLimitRemaining = int.Parse(responseMessage.Headers.GetValues(RateLimitRemainingHeader).First()); response.ResponseText = await responseMessage.Content.ReadAsStringAsync(); return(response); }
private static void SetHeaders(NeoResponse response, HttpWebResponse webResponse) { response.RateLimitTotal = Int32.Parse(webResponse.Headers[RateLimitHeader]); response.RateLimitRemaining = Int32.Parse(webResponse.Headers[RateLimitRemainingHeader]); }
private static bool IsSuccess(NeoResponse response) { return(response.ResponseCode >= 200 || response.ResponseCode < 300); }