zoukankan      html  css  js  c++  java
  • 调用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();
                    }
                }
    
    
    
    
     
  • 相关阅读:
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers
  • 原文地址:https://www.cnblogs.com/lijianhua/p/5558740.html
Copyright © 2011-2022 走看看