コード例 #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(WalletRequest 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     = 2000; // 2 seconds

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

            try
            {
                using (Stream dataStream = webRequest.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("There was a problem sending the request.", ex);
            }

            return(webRequest);
        }
コード例 #2
0
        /// <summary>
        /// Make an JSON RPC request, and return a JSON RPC response object with the result
        /// deserialized as the given type.
        /// </summary>
        /// <typeparam name="T">The type to deserialize the result as.</typeparam>
        /// <param name="walletRequest">The request object.</param>
        /// <returns>A JSON RPC response with the result deserialized as the given type.</returns>
        private WalletResponse <T> MakeRpcRequest <T>(WalletRequest walletRequest)
        {
            HttpWebRequest httpWebRequest = MakeHttpRequest(walletRequest);

            return(GetRpcResponse <T>(httpWebRequest));
        }
コード例 #3
0
        /// <summary>
        /// Make a raw JSON RPC request with the given request object. Returns raw JSON.
        /// </summary>
        /// <param name="walletRequest">The request object.</param>
        /// <returns>The raw JSON string.</returns>
        public string MakeRawRpcRequest(WalletRequest walletRequest)
        {
            HttpWebRequest httpWebRequest = MakeHttpRequest(walletRequest);

            return(GetJsonResponse(httpWebRequest));
        }