微信公众平台api 不能接收来自普通用户的post的消息
我的代码 如下 :请教高手指点。为什么不能接收到消息
public partial class Default : System.Web.UI.Page,IHttpHandler
{
const string Token = "1005sunyafen"; //与那边填写的token一致
protected void Page_Load(object sender, EventArgs e)
{
string postStr = "";
if (Request.HttpMethod.ToLower() == "post") //post方式毕业论文
{
Stream s = Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
postStr = Encoding.UTF8.GetString(b);
if (!string.IsNullOrEmpty(postStr))
{
//封装请求类
XmlDocument doc = new XmlDocument();
doc.LoadXml(postStr);
XmlElement rootElement = doc.DocumentElement;
XmlNode MsgType = rootElement.SelectSingleNode("MsgType");
RequestXML requestXML = new RequestXML();
requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText;
requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;
requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText;
requestXML.MsgType = MsgType.InnerText;
if (requestXML.MsgType == "text")
{
requestXML.Content = rootElement.SelectSingleNode("Content").InnerText;
this.con.InnerText += requestXML.Content; }
else if (requestXML.MsgType == "location")
{
requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText;
requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText;
requestXML.Scale = rootElement.SelectSingleNode("Scale").InnerText;
requestXML.Label = rootElement.SelectSingleNode("Label").InnerText;
}
else if (requestXML.MsgType == "image")
{
requestXML.PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText;
}
//回复消息
ResponseMsg(requestXML);
}
}
else
{
Valid();
}
}
先在这儿调试一下能不能接收到消息
if (!string.IsNullOrEmpty(postStr))
{
就if (Request.HttpMethod.ToLower() == "post") 看看哪步能取到