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, , 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);
}