Post Request PHP Interface
/// <summary> ///Specify the post address get all the strings using Get method/// </summary> /// <param name= "url" >Request a background address</param> /// <returns></returns> Public stringPost (stringURL, sorteddictionary<string,Object>dic) {stringresult =""; HttpWebRequest Request=(HttpWebRequest) webrequest.create (URL); //Signature Encryption stringSign =Sh. Makesign (DIC); Request. Headers.add (" Sign", sign); Request. Headers.add ("Apptype","WinForm"); Request. Headers.add ("Sendtime", Gettimestamp ()); Request. Method="POST"; Request. ContentType="application/x-www-form-urlencoded"; Request. Accept="*/*"; #regionAdd Post ParametersStringBuilder Builder=NewStringBuilder (); inti =0; foreach(varIteminchdic) {if(I >0) Builder. Append ("&"); Builder. AppendFormat ("{0}={1}", item. Key, item. Value); I++; } byte[] data =Encoding.UTF8.GetBytes (builder. ToString ()); Request. ContentLength=data. Length; using(Stream Reqstream =request. GetRequestStream ()) {reqstream.write (data,0, data. Length); Reqstream.close (); } #endregionHttpWebResponse resp; Try{resp=(HttpWebResponse) request. GetResponse (); } Catch(WebException ex) {resp=(HttpWebResponse) ex. Response; } Stream Stream=resp. GetResponseStream (); //Get Response Content using(StreamReader reader =NewStreamReader (Stream, Encoding.UTF8)) {Result=Reader. ReadToEnd (); } returnresult; }
C#post Request PHP Interface