Here is an example of how I used the System.Net.WebClient library to add a feature using JSON. I used http://json2csharp.com/ and the rest API to create an object to hold the add feature result from the server:
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.Headers["Content-type"] = "application/x-www-form-urlencoded";
client.Encoding = System.Text.Encoding.UTF8;
var collection = new System.Collections.Specialized.NameValueCollection
{
{"f", "json"},
{"Token", System.Configuration.ConfigurationManager.AppSettings["TOKEN"]},
{"features", featureParam}
};
byte[] response = client.UploadValues(reqUrl, "POST", collection);
MemoryStream stream = new MemoryStream(response);
StreamReader reader = new StreamReader(stream);
string aRespStr = reader.ReadToEnd();
JavaScriptSerializer jss = new JavaScriptSerializer();
AddResults addResults = jss.Deserialize<AddResults>(aRespStr);
if (addResults == null)
{
GenericError error = jss.Deserialize<GenericError>(aRespStr);
return false;
}
return addResults.addResults.All(addResult=> addResult.success);
}
public class Result
{
public int objectId { get; set; }
public object globalId { get; set; }
public bool success { get; set; }
public Error error { get; set; }
}
public class AddResults
{
public List<Result> addResults { get; set; }
}
Let me know if have any other questions. Hope this helps