示例#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)
            {
                webRequest = null;
                throw _rpcExceptionFactory.GetRpcException(webException);
            }
            catch (RpcException rpcException)
            {
                throw _rpcExceptionFactory.GetRpcException(rpcException);
            }
            catch (Exception exception)
            {
                webRequest = null;
                throw _rpcExceptionFactory.GetRpcException("An unknown exception occured while making json request.", exception);
            }
        }