1.代码
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] data=Encoding.ASCII.GetBytes(String.Format("id={0}&balance={1}",id,balance));
request.ContentLength = data.Length;
request.GetRequestStream().Write(data, 0, data.Length);
request.GetRequestStream().Flush();
request.GetRequestStream().Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr =new StreamReader( response.GetResponseStream() );
2.注意
有因为POST的数据格式有xml,json,form等格式,为了让服务器后台明确数据的格式,最好指明ContentType,否则可能出现服务器接受不到参数
3.附:
form表单格式:application/x-www-form-urlencoded
json格式:json/application
xml格式:text/xml