首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

通过http请求传递xml流和接收xml流的代码示例,该如何处理

2012-09-14 
通过http请求传递xml流和接收xml流的代码示例通过http请求传递xml流和接收xml流的代码示例[解决办法]C# co

通过http请求传递xml流和接收xml流的代码示例
通过http请求传递xml流和接收xml流的代码示例


[解决办法]

C# code
string sampleRequest = @"<?xml version=""1.0""?>你的节点";this.Response = ReceiveData(sampleRequest, Server);            // Load Xml into a XmlDocument object            XmlDocument XmlResponse = new XmlDocument();            try            {                XmlResponse .LoadXml(this.Response);            }            catch            {            }private string ReceiveData(string req, string Server)        {            ASCIIEncoding encoding = new ASCIIEncoding();            byte[] data = encoding.GetBytes(req); // Request            HttpWebRequest r = (HttpWebRequest)WebRequest.Create(Server);             r.Method = "POST";            r.ContentType = "application/x-www-form-urlencoded";            r.ContentLength = data.Length;            Stream requestStream = r.GetRequestStream();            r.Write(data, 0, data.Length);            r.Close();            WebResponse myResponse = null;            string response;            try            {                myResponse = r.GetResponse();                using (StreamReader sr = new StreamReader(myResponse .GetResponseStream()))                {                    response = sr.ReadToEnd();                    sr.Close();                }            }            catch (Exception exc)            {                response = exc.ToString();            }            return response;        } 

热点排行