ASP.NET通過http/https的POST方式,發送和接受XML文件內容


 本文轉載:http://hi.baidu.com/ysyhyt/item/5011ae39ce3cf49fb80c0395

本文參考:http://blog.csdn.net/ououou123456789/article/details/8672962

Response.End();//這一步是關鍵,不輸出帶Html標簽的內容。

ASP.NET通過http/https的POST方式,發送和接受XML文件內容
發送頁面:
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();
接收頁面:
protectedvoid 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();//這一步是關鍵,不輸出帶Html標簽的內容。
}
View Code

 ASP.NET中Request.InputStream使用

http://www.cnblogs.com/zhwl/archive/2012/03/14/2395591.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM