微信公众号post获取xml 报错

Stream inputstream = System.Web.HttpContext.Current.Request.InputStream;
try
{

byte[] b = new byte[inputstream.Length];
inputstream.Read(b, 0, (int)inputstream.Length);
string inputstr = UTF8Encoding.UTF8.GetString(b);
XmlDocument d = new XmlDocument();
d.LoadXml(inputstr);
HttpContext.Current.Response.Write(inputstr);
}
catch(Exception ex)
{
HttpContext.Current.Response.Write(ex);
WriteLog("错误输出:" + ex.ToString());
}

                            提示System.Xml.XmlException: 根级别上的数据无效。 第 1 行,位置 1。 在 System.Xml.XmlTextReaderImpl.Throw(Exception e) 在 System.Xml.XmlTextReaderImpl.Throw(String res, String arg) 在 System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() 在 System.Xml.XmlTextReaderImpl.ParseDocumentContent() 在 System.Xml.XmlTextReaderImpl.Read() 在 System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) 在 System.Xml.XmlDocument.Load(XmlReader reader) 在 System.Xml.XmlDocument.LoadXml(String xml) 在 WebApplication1.weixin.interfaceTest.Index() 位置 e:\百变游戏\BBGame\WebApplication\WebApplication1\weixin\interfaceTest.ashx.cs:行号 149

看下你获取的结构是不是不对

string inputstr 放到try语句外申明,catch中输出inputstr看看结构就知道了,肯定是xml格式有问题了。而且读数据直接下面就行了,干嘛要读到数组中

         if (context.Request.InputStream.Length > 0)
        {
            StreamReader reader = new StreamReader(hc.Request.InputStream, Encoding.UTF8);
            string d = reader.ReadToEnd();
            reader.Close();