C#带参数的POST请求方式
public string Post(string url, Dictionary<string, string> dic,string body="") { string result = ""; StringBuilder builder = new StringBuilder(); foreach (var item in dic) { builder.AppendFormat("{0}={1}", item.Key, item.Value); builder.Append("&"); } url += "?"+builder.ToString()+"t="+DateTime.Now.Second; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/json"; //这个可以添加head //req.Headers.Add("header", "header"); #region 添加Body 内容 byte[] data = Encoding.UTF8.GetBytes(body); req.ContentLength = data.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(data, 0, data.Length); reqStream.Close(); } #endregion HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); //获取响应内容 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); } return result; }