Everything is achievable through technology

Call rest api in c#

private RootObject Sentiment(List sentimentData)
RootObject sentiments = new RootObject();
string data = Newtonsoft.Json.JsonConvert.SerializeObject(sentimentData, Newtonsoft.Json.Formatting.Indented);
data = "{data:" + data + "}";
//System.Net.HttpWebRequest request = System.Net.WebRequest.Create("") as System.Net.HttpWebRequest;
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(""+ConfigurationManager.AppSettings["SentimentAppId"]) as System.Net.HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json"; // "application/json";
Byte[] bt = System.Text.Encoding.UTF8.GetBytes(data);
Stream st = request.GetRequestStream(); st.Write(bt, 0, bt.Length);
using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
if (response.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).", response.StatusCode,
Stream stream1 = response.GetResponseStream();
StreamReader sr = new StreamReader(stream1);
string strsb = sr.ReadToEnd();
sentiments = (RootObject)Newtonsoft.Json.JsonConvert.DeserializeObject(strsb, typeof(RootObject));
return sentiments;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s