Bitnet.Client.BitnetClient.InvokeMethod C# (CSharp) Method

InvokeMethod() public method

public InvokeMethod ( string a_sMethod ) : Newtonsoft.Json.Linq.JObject
a_sMethod string
return Newtonsoft.Json.Linq.JObject
        public JObject InvokeMethod(string a_sMethod, params object[] a_params)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url);
              webRequest.Credentials = Credentials;

              webRequest.ContentType = "application/json-rpc";
              webRequest.Method = "POST";

              JObject joe = new JObject();
              joe["jsonrpc"] = "1.0";
              joe["id"] = "1";
              joe["method"] = a_sMethod;

              if (a_params != null) {
            if (a_params.Length > 0) {
              JArray props = new JArray();
              foreach (var p in a_params) {
            props.Add(p);
              }
              joe.Add(new JProperty("params", props));
            }
              }

              string s = JsonConvert.SerializeObject(joe);
              // serialize json for the request
              byte[] byteArray = Encoding.UTF8.GetBytes(s);
              webRequest.ContentLength = byteArray.Length;

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

              using (WebResponse webResponse = webRequest.GetResponse()) {
            using (Stream str = webResponse.GetResponseStream()) {
              using (StreamReader sr = new StreamReader(str)) {
            return JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
              }
            }
              }
        }