Hardik Dhankecha

Hardik Dhankecha

  • 1.6k
  • 110
  • 5.3k

How to call API from controller with multiple json parameter

Jun 27 2018 4:58 AM
I want to call Web API from controller with multiple json parameter. I don't want to use ajax call for get result.
 
 
  1. var jsonData = "{\"jsonrpc\":2.0," +  
  2.                 "\"method\":eth_blockNumber," +  
  3.                 "\"params\":[]," +  
  4.                 "\"id\":83}";  
  5.   
  6.             HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(string.Format("https://mainnet.infura.io/qhggowRXK7HIgXB0NEyw",jsonData));  
  7.             webreq.Method = "POST";  
  8.             webreq.ContentType = "application/json";  
  9.             using (var streamWriter = new StreamWriter(webreq.GetRequestStream()))  
  10.             {  
  11.                 JavaScriptSerializer serializer = new JavaScriptSerializer();  
  12.                 //var resToWrite = serializer.Deserialize<Dictionary<string, object>>(jsonData);  
  13.                 //streamWriter.Write(jsonData);  
  14.                 streamWriter.Flush();  
  15.                 streamWriter.Close();  
  16.             }  
  17.             WebResponse response = webreq.GetResponse();  
  18.             var streamReader = new StreamReader(response.GetResponseStream());  
  19.             var result = streamReader.ReadToEnd();  

Answers (1)