HttpWebRequest request = WebRequest.Create ("http://192.168.0.99:8080/wzh-webservice/rest/login?username=shuenjia&password=123456") asHttpWebRequest;//Rest/loginRequest. 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 (); stringresp; Try { using(HttpWebResponse response = Request.) GetResponse () asHttpWebResponse) {StreamReader SR=NewStreamReader (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 ("parameter"); 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 (); } }
Invoking the Java rest Ful interface instance