- /// <summary>
- /// 发送消息到服务器
- /// </summary>
- /// <param name="xmldata">需要发送的消息</param>
- /// <param name="url">服务器地址</param>
- /// <returns>服务器返回的消息</returns>
- public static string SendByPOST(string xmldata, string url)
- {
- string sXmlMessage = xmldata;
- string DsmpUrl = url;
- Encoding encode = System.Text.Encoding.GetEncoding("gb2312");
- byte[] arrB = encode.GetBytes(sXmlMessage);
- HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(DsmpUrl);
- myReq.Method = "POST" ;
- myReq.ContentType = "application/x-www-form-urlencoded";
- myReq.ContentLength = arrB.Length;
- Stream outStream = myReq.GetRequestStream();
- outStream.Write(arrB, 0, arrB.Length);
- outStream.Close();
- WebResponse myResp = myReq.GetResponse();
- Stream ReceiveStream = myResp.GetResponseStream();
- StreamReader readStream = new StreamReader( ReceiveStream, encode);
- Char[] read = new Char[256];
- int count = readStream.Read(read, 0, 256);
- string str = null;
- while (count > 0)
- {
- str += new String(read, 0, count);
- count = readStream.Read(read, 0, 256);
- }
- readStream.Close();
- myResp.Close();
- return str;
- }
c# Post 通过HttpWebRequest 网页通信
最新推荐文章于 2025-08-14 21:27:18 发布