Wednesday, July 23, 2014

consume rest web service in c#

 WebRequest req = WebRequest.Create("url");
            string postData = "sessionName=TechJamSessionAtCurologic&fromDate=1-7-2014&toDate=1-7-2014&sessionScheduleId=6";

            byte[] send = Encoding.Default.GetBytes(postData);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = send.Length;

            Stream sout = req.GetRequestStream();
            sout.Write(send, 0, send.Length);
            sout.Flush();
            sout.Close();

            WebResponse res = req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream());
            string returnvalue = sr.ReadToEnd();

URL Example - http://hostname/Methodname

No comments:

Post a Comment