http://CC318.com

一个程序的窝

我的窝窝 http://CC318.com 这里有更多内容,不信你试试.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

通过http/https的POST方式,发送和接受XML文件内容

Posted on 2009-02-13 11:10  chaoliu  阅读(737)  评论(0)    收藏  举报
发送页面:
C# code
string strXML = "<root><a>test112</a></root>";

System.Net.WebClient wc
= new System.Net.WebClient();

byte[] bs = System.Text.Encoding.Default.GetBytes(strXML);
byte[] bsReturn = wc.UploadData("http://localhost/test/webform2.aspx", bs);


string strReturn = System.Text.Encoding.Default.GetString(bsReturn);
Response.Write(strReturn);

Response.End();

  接收页面:

 
C# code
protected void Page_Load(object sender, EventArgs e)
{



System.Xml.XmlDocument dom
= new System.Xml.XmlDocument();
try
{
dom.Load(Request.InputStream);
System.Xml.XmlNode node
= dom.SelectSingleNode("//a");
if (node != null)
{
Response.Write(
"nodeValue=" + node.InnerText);
}
}
catch
{
Response.Write(
"发生错误!");

}
Response.End();


}
http://CC318.com