예제 #1
0
        /// <summary>
        /// Make the actual HTTP request to the Bitcoin RPC interface.
        /// </summary>
        /// <param name="walletRequest">The request to make.</param>
        /// <returns>The HTTP request object.</returns>
        private HttpWebRequest MakeHttpRequest(DaemonRequest walletRequest)
        {
            var webRequest = (HttpWebRequest)WebRequest.Create(RpcUrl);

            webRequest.Credentials = new NetworkCredential(RpcUser, RpcPassword);

            // Important, otherwise the service can't deserialse your request properly
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method      = "POST";
            webRequest.Timeout     = _timeout;

            _logger.Verbose("tx: {0}", Encoding.UTF8.GetString(walletRequest.GetBytes()).PrettifyJson());

            byte[] byteArray = walletRequest.GetBytes();
            webRequest.ContentLength = byteArray.Length;

            try
            {
                using (Stream dataStream = webRequest.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();
                }
            }
            catch (WebException webException)
            {
                throw _rpcExceptionFactory.GetRpcException(webException);
            }
            catch (Exception exception)
            {
                throw _rpcExceptionFactory.GetRpcException("An unknown exception occured while making json request.", exception);
            }

            return(webRequest);
        }
예제 #2
0
        /// <summary>
        /// Make the actual HTTP request to the Bitcoin RPC interface.
        /// </summary>
        /// <param name="walletRequest">The request to make.</param>
        /// <returns>The HTTP request object.</returns>
        private HttpWebRequest MakeHttpRequest(DaemonRequest walletRequest)
        {
            RequestsMeter.Mark();

            var webRequest = (HttpWebRequest)WebRequest.Create(RpcUrl);

            webRequest.Credentials = new NetworkCredential(RpcUser, RpcPassword);

            // Important, otherwise the service can't deserialse your request properly
            webRequest.UserAgent   = string.Format("CoiniumServ {0:} {1:}", VersionInfo.CodeName, Assembly.GetAssembly(typeof(Program)).GetName().Version);
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method      = "POST";
            webRequest.Timeout     = _timeout;

            _logger.Verbose("tx: {0}", Encoding.UTF8.GetString(walletRequest.GetBytes()).PrettifyJson());

            byte[] byteArray = walletRequest.GetBytes();
            webRequest.ContentLength = byteArray.Length;

            try
            {
                using (Stream dataStream = webRequest.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }

                return(webRequest);
            }
            catch (WebException webException)
            {
                _logger.Error(webException, "WebException on MakeHTTPRequest");
                webRequest = null;
                throw _rpcExceptionFactory.GetRpcException(webException);
            }
            catch (Exception exception)
            {
                webRequest = null;
                _logger.Error(exception, "Exception occured while making json request");
                throw _rpcExceptionFactory.GetRpcException("An unknown exception occured while making json request.", exception);
                //return webRequest;
            }
        }