Created
August 13, 2011 06:07
-
-
Save bkono/1143528 to your computer and use it in GitHub Desktop.
Call a JSON Rest Service from c# with Newtonsoft.Json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private dynamic CallRestService(string uri, string method, dynamic parms) { | |
dynamic result; | |
var req = HttpWebRequest.Create(uri); | |
req.Method = method; | |
req.ContentType = "application/json"; | |
byte[] bytes = UTF8Encoding.UTF8.GetBytes(parms.ToString()); | |
req.ContentLength = bytes.Length; | |
using (var stream = req.GetRequestStream()) { | |
stream.Write(bytes, 0, bytes.Length); | |
} | |
using (var resp = req.GetResponse()) { | |
var results = new StreamReader(resp.GetResponseStream()).ReadToEnd(); | |
result = JObject.Parse(results); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment