Page 1
Page 2
Page 3
Sending XML using XMLHTTP object
The XMLHTTP object handles the transfer
of XML documents over HTTP which is the most widely used
in the internet. It uses GET, POST, PUT, or PROPFIND method
to upload XML document to the server. This object uses "open"
method to open a connection to the URL, "send"
method to upload the XML document to the server and "responseXML"
property to get the XML document back to from server. The
"responseXML" is a DOMDocument object which you
can directly load into a MSXML DOMDocument object at the
server end. Look into more details information about this
object in the XML SDK documentation from Microsoft. For
this article, we are going to use the "responseText"
property to display the confirmation message returned from
the server.
The additional code in the eVB program
In the previous article, I finished
after saving the XML file locally. Now let's write the code
to upload the XML content to the web server.
First we are going to check whether
the XML document needs to be sent to other servers or whether
it's going to be saved in the local system. We just check
if there exists any "uploadpath" in the current
XML document.
uploadpath = xmlDoc.DocumentElement.selectSingleNode("param[@id='uploadpath']").Text
If uploadpath = "" Then Exit Sub
What the above statements does is that
it looks for any XML node named "param" which
has a "id" named "uploadpath". If the
upload path does not exist then we just leave the function.
Lets assume that we have the "uploadpath".
So lets create the XMLHTTP object.
Set objXMLHttp = CreateObject("Microsoft.XMLHTTP")
Now set the XML upload path, HTTP method
and mode.
objXMLHttp.Open "POST", uploadpath,
False
The last parameter is the mode of data
transfer, synchronous or asynchronous.
And send the XML data to the specified
URL and wait for the response from the server:
objXMLHttp.send xmlDoc.xml
MsgBox objXMLHttp.responseText, vbOKOnly, "Pizza order"
You will get the information back from
the ASP pages created by "Response" object which
will be:
File Uploaded Successfully
Phone:
Or the error message generated by the
ASP pages.
What does the MSXML write to the
web server?
This is really interesting. I tested
the MSXML parser with a small java program to find out what
it actually writes to a web server. The java program is
really simple. It simply captures a port and waits for any
response from the client program. Here is the output after
uploading the content to the web server( this one is the
dummy one ).
POST /shakil/test.asp HTTP/1.1
Content-Length: 1233
User-Agent: Mozilla/2.0 (compatible; MSIE 3.02; Windows
CE; 240x320)
Host: 127.0.0.1:8088
Connection: Keep-Alive
<?xml version="1.0"?>
<orderform>
<param id="uploadpath">http://127.0.0.1:8088/shakil/test.asp</param>
Name:<input type="text" name="cli_name"
value="Shakil Ahmed Siraj"/><br/>
Address:<br/>
<textarea name="cli_address" rows="3">Dhaka</textarea><br/>
Phone:<input type="text" name="cli_phone"
value="+88019311041"/><br/>
Pizza:<br/>
<select name="cli_pizza" multiple="true">
<option value="1" selected="true">The
Edge</option>
<option value="2" selected="true">Stuffed
Crust</option>
<option value="3" selected="false">The
Italian</option>
<option value="4" selected="false">Pan
Pizza</option>
</select><br/>
Toppings:<br/>
<select name="cli_topings" multiple="false">
<option value="1" selected="true">Oil,
olives and mushrooms</option>
<option value="2" selected="false">Shredded
veggies topped with a favorite salad dressing</option>
<option value="3" selected="false">Tuna,
onions and veggie oil, salt and pepper</option>
</select><br/>
Delivery:<br/>
<input type="radio" name="cli_delivery"
checked="true"/>Delivery<br/>
<input type="radio" name="cli_delivery"
checked="false"/>Table<br/>
<input type="radio" name="cli_delivery"
checked="false"/>Take Away<br/>
</orderform>
This is just to explain you why we need
to get the entire content of the "Request" object
in the ASP page. The first paragraph is the identification
of the client browser and it's capabilities as required
in the HTTP protocol. The second portion is the data that
was sent to the web server.
Conclusion
The objective of this article is to
show you how easily you can transfer data from a small handheld
device to a web server connected to Intranet/Internet. We
are just using the components that comes built-in with WinCE
and this kind of approach makes sense since all the development
tools are moving toward XML. Using EVB and MSXML parser,
you can even write programs that actually synchronizes databases
over the network. Though the possibilities are limitless,
It is up to you to decide how you are going to use them
in your program. Best of luck.
Previous Page