Client/Server Data Exchange over HTTP using XMLHTTP


The example requires Internet Explorer 5+ and XMLHTTP

Moving data over HTTP has meant using JAVA, Remote Scripting, Remote Data Services, the Internet Data Control, and more recently, MSMQ.
These technologies often required major updates to the client side or lots of code to implement.
XMLHTTP is very simple in comparison.

Let's say you want to send a bunch of data to the server--

sub sendbutton_onclick()
'   collect the data you want to send
'   make up an XML version (mydoc)
'     this might include serialization, compression, bin64 encoding, etc.

set xmlhttp= createobject("Microsoft.XMLHTTP")
xmlhttp.open "POST",URL,false      '   URL is an ASP page set up to receive this XML document
xmlhttp.send mydoc                        '   false requests synchronous I/O
gotback= xmlhttp.responseText

'   process return, display user messages or page updates

end sub


On the server side, an ASP document (XMLRecvr) receives the XML document

<%
dim xmldoc
on error resume next
set xmldoc = Server.CreateObject("Msxml.DOMDocument")
xmldoc.async= false
xmldoc.load(Request)
set root= xmldoc.documentelement

'   process the document
'   write to a database, validate, etc.
response.write myresponse
set xmldoc= nothing
response.end
%>

The tecnology supports asynchronous calls as well.

Getting data from the server is equally simple.

sub getbutton_onclick()
on error resume next set xmldoc = CreateObject("Msxml.DOMDocument")
set xmlHTTP= createobject("Microsoft.XMLHTTP")
xmlHTTP.open "GET",URL      '   URL is an ASP page set up to send an XML document
xmlHTTP.send()
mydoc= xmlHTTP.responsetext
xmldoc.loadxml mydoc
set root= xmldoc.documentelement

'   parse the document
'   update the user's page

set xmlHTTP= nothing
set xmldoc= nothing
end sub

On the server the ASP document at the specified URL world return an XML Document.

<%
dim xmldoc
on error resume next
set xmldoc = Server.CreateObject("Msxml.DOMDocument")

'   form up the XML document

Response.ContentType= "text/xml"
Response.Write "<?xml version=""1.0"" ?>"+vbcrlf
Response.Write xmldoc.textxml
set xmldoc= nothing
response.end
%>


I'll get an example here soon. (10/15/2001)


Key Words

Index to Pages