Difference between revisions of "Template:Base Code for Consuming API Using CSharp"
From Updox API
(Created page with " private void SendReceiveJSON(string json, string url) { var httpWebRequest = WebRequest.Create(url); httpWebRequest.ContentType = "text/jso...") |
|||
(2 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | + | private void SendReceiveJSON(string json, string url) | |
− | + | { | |
− | + | var httpWebRequest = WebRequest.Create(url); | |
− | + | httpWebRequest.ContentType = "application/json"; | |
− | + | httpWebRequest.Method = "POST"; | |
− | + | using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) | |
− | + | { | |
− | + | streamWriter.Write(json); | |
− | + | streamWriter.Flush(); | |
− | + | streamWriter.Close(); | |
− | + | var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse(); | |
− | + | using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) | |
− | + | { | |
− | + | var result = streamReader.ReadToEnd(); | |
− | + | } | |
− | + | } | |
− | + | } |
Latest revision as of 14:11, 18 November 2013
private void SendReceiveJSON(string json, string url) { var httpWebRequest = WebRequest.Create(url); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); } } }