示例#1
0
        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);
        }
示例#3
0
 private static void SetHeaders(NeoResponse response, HttpWebResponse webResponse)
 {
     response.RateLimitTotal     = Int32.Parse(webResponse.Headers[RateLimitHeader]);
     response.RateLimitRemaining = Int32.Parse(webResponse.Headers[RateLimitRemainingHeader]);
 }
示例#4
0
 private static bool IsSuccess(NeoResponse response)
 {
     return(response.ResponseCode >= 200 || response.ResponseCode < 300);
 }