public static string PostWebRequest2() { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://183.66.231.18:8184/api/services/app/ChildSystem/checkLogin");//这是你要提交的url Encoding encoding = Encoding.UTF8; IDictionary<string, string> para = new Dictionary<string, string>(); para.Add("ticket", "22d0a6a46bbdf44ec718f600b012b261"); StringBuilder buffer = new StringBuilder();//这是要提交的数据 int i = 0; foreach (string key in para.Keys) { if (i > 0) { buffer.AppendFormat("&{0}={1}", key, para[key]); } else { buffer.AppendFormat("{0}={1}", key, para[key]); } i++; } byte[] bs = Encoding.UTF8.GetBytes(buffer.ToString());//UTF-8 string responseData = String.Empty; req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; req.ContentLength = bs.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); reqStream.Close(); } using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { responseData = reader.ReadToEnd().ToString(); return responseData; } } }
对应的 Postman 界面