Exemplo n.º 1
0
        protected string ExecuteRequest(params object[] @params)
        {
            string content = string.Empty;
            HttpResponseMessage response = null;
            var method      = GetNameCallMethod(nameof(ExecuteRequest));
            var request     = 0 != @params.Length ? new BitcoinNetRequest(method, @params) : new BitcoinNetRequest(method);
            var jsonRequest = JsonConvert.SerializeObject(request);

            try
            {
                using (var client = GetHttpClient())
                    using (response = client
                                      .PostAsync(Server, new StringContent(jsonRequest, Encoding.UTF8, "application/json-rpc")).Result)
                    {
                        content = response.Content.ReadAsStringAsync().Result;
                        response.EnsureSuccessStatusCode();
                    }
            }
            catch (HttpRequestException)
            {
                throw new JsonRpcException(BaseResponseStatus.Create(Convert.ToInt32(response.StatusCode), content));
            }
            catch (Exception exception)
            {
                throw new JsonRpcException(BaseResponseStatus.Create(500, exception.Message));
            }
            return(content);
        }
 public JsonRpcException(BaseResponseStatus status) : base(status.Message)
 {
     Status = status;
 }