日期:2014-05-17  浏览次数:20464 次

求解 asp.net 获取post 微信xml数据
已写代码 如下
protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.HttpMethod.ToLower() == "post")
            {
                Stream s = System.Web.HttpContext.Current.Request.InputStream;
                byte[] b = new byte[s.Length];
                s.Read(b, 0, (int)s.Length);
                string postStr = Encoding.UTF8.GetString(b);
                if (!string.IsNullOrEmpty(postStr))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(postStr);
                    XmlNodeList list = doc.GetElementsByTagName("xml");
                    XmlNode xn = list[0];
                    string FromUserName = xn.SelectSingleNode("//FromUserName").InnerText;
                    string ToUserName = xn.SelectSingleNode("//ToUserName").InnerText;
                    string content = "", menu = "";
                    content = xn.SelectSingleNode("//Content").InnerText;

                    if (content.Equals("HelloV2V"))
                    {
                        menu = "欢迎xxx";
                    }
                    else
                    {
                        menu = "现在是北京时间:" + string.Format("{0:f}", DateTime.Now);
                    }
&nb