Problems with xmlhttp
I have the following code to grab details from a webserver
<%@ LANGUAGE=VBScript%>
<%
vCustomerUserName = "name"
vCustomerPassword = "password"
vEventID = 123456
vEmail = "myname@me.com"
vPassword = "1122334455"
Response.Buffer=False
Dim MyConnection
Dim TheURL
''# Specifying the URL
dataURL = "http://www.regonline.com/authorization.asmx/authorizeMemberWithEmailAddress"
Set MyConnection = Server.CreateObject("Microsoft.XMLHTTP")
''# Connecting to the URL
MyConnection.Open "POST", dataURL, False
MyConnection.setRequestHeader "Content-type", "application开发者_如何学编程/x-www-form-urlencoded"
''# Sending and getting data
strQueryString = "customerUserName=" & vCustomerUserName & "&customerPassword=" & vCustomerPassword & "&eventID=" & vEventID & "&emailAddress=" & vEmail & "&password=" & vPassword
''# MyConnection.Send
MyConnection.Send strQueryString
TheData = MyConnection.responseText
''# Set the appropriate content type
Response.ContentType = MyConnection.getResponseHeader("Content-type")
Response.Write (TheData)
Set MyConnection = Nothing
%>
If I run this page in a browser it returns what appears to be an xml document. What I need to do is extract the value of a particular node and then send that to the browser in the form
response.write firstName=bob&lastName=smith
Could anyone please help me this is driving me mad and has taken a LONG time so far to get nowhere. I don't seem to be able to access the reply from the server as an xml document and would appreciate any help.
Thanks
You can use the responseXML property instead of responseText
. It is an instance of an IXMLDOMDocument object. You can then use XPath to select out the data you need via the selectSingleNode
method.
This will not work if the content type of the response is not set to text/xml
or application/xml
. If this is the case, you can still use MSXML to load the responseText into a DOMDocument and select the data you need.
Another thing to note is that it is generally not recommend to use the XMLHTTP obect from a server side application. It is meant to be used from the client side, because in depends on WinInet. You should use ServerXMLHttp instead. It has the same functionality, but depends on WinHTTP as opposed to WinInet. See the FAQ for more information.
精彩评论