1. Submit binary Stream data (in JSON format):
varDIC =Newsorteddictionary<string,string> { {"name","Test"}, {"Pass","123"}, }; //Serialization Parameters varJsonparam =Jsonconvert.serializeobject (DIC); //Send Request varRequest =(HttpWebRequest) webrequest.create (URL); Request. Method="POST"; Request. ContentType="Application/json;charset=utf-8"; varBytedata =Encoding.UTF8.GetBytes (Jsonparam); varLength =bytedata.length; Request. ContentLength=length; varwriter =request. GetRequestStream (); Writer. Write (Bytedata,0, length); Writer. Close (); //Receive Data varResponse =(HttpWebResponse) request. GetResponse (); varResponsestring =NewStreamReader (response. GetResponseStream (), Encoding.GetEncoding ("Utf-8")). ReadToEnd ();
2. Submit Form Method One:
varURL ="xxxxxxxxxxxxxxxxxxxxxx"; varWebclientobj =NewWebClient (); varPostvars =NewNameValueCollection {{"name","Test"}, {"Pass","123"} }; byte[] byremoteinfo = webclientobj.uploadvalues (URL,"POST", Postvars); stringJSON = Encoding.UTF8.GetString (byremoteinfo);
3, submit the form method two:
varURL ="xxxxxxxxxxxxxxxxxxxxxxx"; //by grasping the package tool, you can see that this is the format varPostData ="username=test&password=123"; HttpWebRequest req=(HttpWebRequest) webrequest.create (URL); Req. Method="POST"; Req. Timeout=30000; Req. AllowAutoRedirect=false; Req. ContentType="application/x-www-form-urlencoded"; Req. KeepAlive=true; byte[] Postbytes =Encoding.UTF8.GetBytes (postdata); Req. ContentLength=postbytes.length; Stream Postdatastream=req. GetRequestStream (); Postdatastream.write (Postbytes,0, postbytes.length); Postdatastream.close (); HttpWebResponse resp= (HttpWebResponse) req. GetResponse ();
C#post Submit