Client
<script language= "JavaScript" >
Generate XML file
function Getallformdata ()
{
var strxml = "<client>\r\n<formdata>\r\n";
Strxml = "<UserName>bccu</UserName>"
Strxml = "<Age>25</Age>";
Strxml = "</FormData>\r\n</Client>"
return strxml;
}
Send an XML document to a service
function Send (Str,url)
{
var Http = new ActiveXObject ("Microsoft.XMLHTTP")
Http.open ("POST", Url,false)
Http.send (STR)
return http.responsetext;
}
Gets the value of the section specified in the XML
function Getxmlnodevalue (strxml,nodename)
{
var Dom = new ActiveXObject ("Microsoft.XMLDOM")
Dom.async=false
Dom.loadxml (Strxml)
if (Dom.parseError.errorCode!= 0)
{
Delete (Dom)
Return (false)
}
Else
{
var node = Dom.documentElement.selectSingleNode ("//" +nodename);
if (node)
NodeValue = Node.text;
Delete (Dom)
return (NodeValue);
}
}
function Test ()
{
var tmp = Send (Getallformdata (), "./test.aspx");
var name = Getxmlnodevalue (tmp, "UserName");
var password = getxmlnodevalue (tmp, "age");
}
</script>
Server Side (Test.cs)
System.IO.Stream Stream = Request.inputstream
System.Xml.XmlDocument doc = new XmlDocument ();
Try
{
Doc. Load (stream); Load the XML document sent over
}
Catch
{
byte[] buffer = new Byte[stream. Length];
Stream. Read (Buffer,0,buffer. Length);
String strxml = System.Text.UnicodeEncoding.Default.GetString (buffer,0,buffer. Length);
Doc. Loadxml (strxml);
}
Output doc after processing to return to the client (omitted here)
Response.Write ("")
Http://www.cnblogs.com/bccu/archive/2006/08/04/467548.html