调用java rest ful 接口实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调用java rest ful 接口实例相关的知识,希望对你有一定的参考价值。
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 接口实例的主要内容,如果未能解决你的问题,请参考以下文章
java调用restful api接口,有没有啥好的框架推荐