好的,这是我的替代答案,这次您请求的页面将 XML 字符串发送到另一个页面,该页面将其加载到 XML 文档中并从 XML 中提取数据。
[编辑]您在原始帖子中用于发送 XML 的技术工作正常,请参阅下面显示的最终版本 (post3.asp /receive3.asp)。
在 post2.asp / receive2.asp 中,我将 XML 编码为名为 XML 的表单字段,然后将该字段加载到接收端的 XML 对象中。这适用于相对较小的 XML 文件。
在这个例子中,你必须请求 post2.asp 页面:
post2.asp
<%
Response.write "Posting XML data to another page<br/>"
'// URL to which to send XML data
URL="http://localhost:8096/pages/test/receive2.asp"
'// The XML string to be sent
Dim Information: Information = "<Send><UserName>Colt</UserName><PassWord>Taylor</PassWord><Data>100</Data></Send>"
dim XMLHttp : SET XMLHttp = Server.CreateObject("MSXML2.ServerXMLHttp")
xmlhttp.Open "POST", url, false
xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
'// URLEncode the XML into a form data string and send it
xmlhttp.send "xml=" & server.URLEncode( Information )
'// Get the response that is send by receive2.asp
dim sResponse: sResponse = xmlhttp.ResponseText
'// Show the response
Response.write "Response received from the called page:<hr/><span style='color:blue'>" & sResponse & "</span><hr/>"
%>
Receive2.asp
<%
'// Get the xml string from the request
xml = Request.form("xml")
'// Write the received XML as a displayable html string
response.write "[" & replace(replace(xml, "<", "<"), ">", ">") & "]<br/>"
'// Create the XML object to load the string
Dim objXml
Set objXml = Server.CreateObject("MSXML2.DOMDOCUMENT.3.0")
'// Try to load the xml string
if objXML.LoadXML(xml) THEN
'// Get the data from the xml
strQuery = "//UserName"
Set oNode = objXML.selectSingleNode(strQuery)
strUserName = oNode.Text
'// Success message
response.write "success - user = " & strUserName & "<br/>"
ELSE
'// Failed message
Response.Write "Failed to load XML file, reason: " & objXML.parseError.reason & "<br/>"
END IF
%>
这是你打开post2.asp页面时得到的结果
Posting XML data to another page
Response received from the called page:
_______________________________________________________
[<Send><UserName>Colt</UserName><PassWord>Taylor</PassWord><Data>100</Data></Send>]
success - user = Colt
_______________________________________________________
这是最终版本,这次使用 XML 内容类型。你要打开post3.asp页面:
Post3.asp
<%
'// URL to which to send XML data
URL="http://localhost:8096/pages/test/receive3.asp"
Response.Write "Sending XML data to " & URL & "<br/>"
information = "<Send><UserName>Colt</UserName><PassWord>Taylor</PassWord><Data>100</Data></Send>"
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.send information
'// Report the response from the called page
response.write "Response received:<hr/><span style='color:blue'>" & xmlhttp.ResponseText & "</span><hr/>"
%>
Receive3.asp
<%
Dim objXmlRequest
Set objXmlRequest = Server.CreateObject("MSXML2.DOMDOCUMENT.3.0")
IF objXmlRequest.Load (Request) THEN
'GET THE REQUEST FROM CLIENT
strQuery = "//UserName"
Set oNode = objXmlRequest.selectSingleNode(strQuery)
strActionName = oNode.Text
response.write "success! user name is " & strActionName
ELSE
Response.Write "Failed to load XML file, reason: " & objXmlRequest.parseError.reason
END IF
%>
结果是:
Sending XML data to http://localhost:8096/pages/test/receive3.asp
Response received:
success! user name is Colt