C#发送和接受POST请求
1、发送Post请求代码
/// <summary> /// 发起Http请求 /// </summary> /// <param name="flightData">发送航班对象</param> public static void HttpRequest(string url, string para) { byte[] bs = Encoding.UTF8.GetBytes(para); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = bs.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); } string strResponse = string.Empty; using (WebResponse wr = req.GetResponse()) { StreamReader responseStream = new StreamReader(wr.GetResponseStream(), Encoding.GetEncoding("utf-8")); strResponse = responseStream.ReadLine(); } }
2、接受Post请求
if (!string.IsNullOrEmpty(this.Request.Form.ToString())) { string str = HttpUtility.UrlDecode(this.Request.Form.ToString(), Encoding.UTF8); }
作者:BestNow
出处:http://www.cnblogs.com/BestNow/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/BestNow/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。