Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


Global Lending
2016-02-17T20:23:40Z
Hopefully this will be helpful to someone else.

We needed to send a http post with a content-type of application/json and parse a JSON string from the http response. I used the .Net Code Execute task to make the call and to parse the JSON returned. Below is the code generalized to allow for easy customization. Be sure to include a reference to System.Runtime.Serialization.dll and System.Web.Extensions.dll. Here is a links to a MSDN article on JSON serialization
 


using System;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;

public class Test
{
	public class YourClass
	{
		public string someValue= "";
		public string otherValue = "";
		public string differentValue = "";
		
	}
	
 public static string GetKey()
 {     
     var yc = new YourClass();
     string requestBody = "{\"someValue\": \"this is some data\",\"otherValue\": \"other data appears here\",\"differentValue\": \"different data \"}";
     string endpoint = "https://someendpoint/api";
     
     // set up the Http request
     var yourHttpRequest = (HttpWebRequest)WebRequest.Create(endpoint);
     yourHttpRequest.ContentType = "application/json";
     yourHttpRequest.Method = "POST";
     
     // write the body of the http request
     using (var sw = new StreamWriter(yourHttpRequest.GetRequestStream()))
     {
     	sw.Write(requestBody);
     	sw.Flush();
     	sw.Close();
     }
     
     // get and parse the response
     using (var yourHttpResponse = (HttpWebResponse)yourHttpRequest.GetResponse()) {
    	
       // parse the json returned
    	using (var reader = new StreamReader(yourHttpResponse.GetResponseStream())){
    		JavaScriptSerializer js = new JavaScriptSerializer();
    		var objText = reader.ReadToEnd();
    		yc = js.Deserialize<YourClass>(objText);
    		
    	}
    	
    }
    
     return yc.someValue;
 }




}
Sponsor
Forum information
Support
2016-02-22T11:07:37Z
Thanks for sharing!
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Support
2017-09-29T14:44:28Z
We have now added a JSON Task supporting JSONPath and JQ format:

https://www.visualcron.c....aspx?g=posts&t=7604 
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top