Note the combination of the parameters of the post
HttpWebRequest request = webrequest.create (URL) asHttpwebrequest;request. Method="POST"; request. KeepAlive=true; request. AllowAutoRedirect=false; request. ContentType="application/x-www-form-urlencoded";byte[] Postdatabtyes = Encoding.UTF8.GetBytes ("param={"Imsi":"460023887603775","Session":"Hwjpcfmgnrtyoed91itwptecy"}"); 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 (); } }
Another type of:
2, post to getusingsystem.web; Uri Address=NewUri ("http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction"); //Create the Web requestHttpWebRequest request = WebRequest.Create (address) asHttpWebRequest; //Set type to POSTRequest. Method ="POST"; Request. ContentType="application/x-www-form-urlencoded"; //Create The data we want to send stringAppId ="Yahoodemo"; stringContext ="Italian sculptors and painters of the Renaissance"+"favored the Virgin Mary for inspiration"; stringquery ="Madonna"; StringBuilder Data=NewStringBuilder (); Data. Append ("appid="+Httputility.urlencode (appId)); Data. Append ("&context="+Httputility.urlencode (context)); Data. Append ("&query="+httputility.urlencode (query)); //Create A byte array of the data we want to send byte[] Bytedata =UTF8Encoding.UTF8.GetBytes (data. ToString ()); //Set The content length in the request headersRequest. ContentLength =bytedata.length; //Write Data using(Stream Poststream =request. GetRequestStream ()) {Poststream.write (bytedata,0, bytedata.length); }//Get Response using(HttpWebResponse response = Request.) GetResponse () asHttpWebResponse) {//Get the response streamStreamReader reader =NewStreamReader (response. GetResponseStream ()); //Console Application OutputConsole.WriteLine (reader. ReadToEnd ()); HTTP authentication request Some friends may want to provide the user name and password for HTTP authentication when calling the RESTful API, where we can do this by adding a networkcredentials instance to the request. //Create the Web requestHttpWebRequest Request= WebRequest.Create ("https://api.del.icio.us/v1/posts/recent") asHttpWebRequest; //ADD authentication to requestRequest. Credentials =NewNetworkCredential ("username","Password"); //Get Response using(HttpWebResponse response = Request.) GetResponse () asHttpWebResponse) {//Get the response streamStreamReader reader =NewStreamReader (response. GetResponseStream ()); //Console Application OutputConsole.WriteLine (reader. ReadToEnd ()); }
. NET calling Java Rest ful API instances