码迷,mamicode.com
首页 > 编程语言 > 详细

调用java rest ful 接口实例

时间:2016-06-04 15:00:39      阅读:533      评论:0      收藏:0      [点我收藏+]

标签:

HttpWebRequest request = WebRequest.Create("http://192.168.0.99:8080/wzh-webservice/rest/login?username=shuenjia&password=123456") as HttpWebRequest;//rest/login
            request.Method = "post";
            request.KeepAlive = true;
            request.Method = "getUserInfoByNameAndPwd";
            request.AllowAutoRedirect = false;
            request.ContentType = "application/x-www-form-urlencoded";
            byte[] postdatabtyes = Encoding.UTF8.GetBytes("param={\"username\":\"shuenjia\",\"password\":\"123456\"}");
            request.ContentLength = postdatabtyes.Length;
            Stream requeststream = request.GetRequestStream();
            requeststream.Write(postdatabtyes, 0, postdatabtyes.Length);
            requeststream.Close();
            string resp;
            try
            {
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    resp = sr.ReadToEnd();
                }
            }
            catch
            {
            }


HttpWebRequest request = WebRequest.Create("http://") as HttpWebRequest;
            request.Credentials = new NetworkCredential("123", "123");
            request.Method = "POST";
            request.KeepAlive = true;
            request.AllowAutoRedirect = false;
            request.ContentType = "application/x-www-form-urlencoded";
            byte[] postdatabtyes = Encoding.UTF8.GetBytes("参数");
            request.ContentLength = postdatabtyes.Length;
            Stream requeststream = request.GetRequestStream();
            requeststream.Write(postdatabtyes, 0, postdatabtyes.Length);
            requeststream.Close();
            string resp;
            try
            {
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    resp = sr.ReadToEnd();
                }
            }

 

 

 

调用java rest ful 接口实例

标签:

原文地址:http://www.cnblogs.com/lijianhua/p/5558740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!