一、整體方案介紹
說明: VB客戶端使用msxml.dll組件,創建XMLHTTP對象,通過該對象以HTTP方式訪問WebServer請求,提交數據并取得返回的數據結果
二、如何使用MSXML組件進行開發
a) MSXML組件引入項目
MSXML組件引入項目比較簡單,方法如下圖所示:
注:建議使用MSXML v6.0版本,如果本地沒有可上官網上下載。
客戶端代碼編寫
1 Dim xmlhttp As XMLHTTP60
2 Set xmlhttp = New XMLHTTP60
3
4 Dim url As String
5 url = “http://localhost:8080/simplewebapps/jsp/test.jsp”
6 Dim postData As String
7 postData = “<data><value>post data提交數據</value></data>”
8
9 xmlhttp.open "POST", url, False
10 xmlhttp.setRequestHeader "User-Agent", "MyCustomUser"
11
12 If IsNull(postData) Then
13 xmlhttp.send
14 Else
15 xmlhttp.send postData
16 End If
17
18 Dim responseText AS String
19 ‘解析返回的xml數據格式
20 responseText = xmlhttp.responseText
21
22 Set xmlhttp = Nothing
23
2 Set xmlhttp = New XMLHTTP60
3
4 Dim url As String
5 url = “http://localhost:8080/simplewebapps/jsp/test.jsp”
6 Dim postData As String
7 postData = “<data><value>post data提交數據</value></data>”
8
9 xmlhttp.open "POST", url, False
10 xmlhttp.setRequestHeader "User-Agent", "MyCustomUser"
11
12 If IsNull(postData) Then
13 xmlhttp.send
14 Else
15 xmlhttp.send postData
16 End If
17
18 Dim responseText AS String
19 ‘解析返回的xml數據格式
20 responseText = xmlhttp.responseText
21
22 Set xmlhttp = Nothing
23
服務器代碼編寫(Jsp示例)
1 <%
2 //取得提交的參數
3 String postData = “”;
4 String str;
5 While ( (str = request.getReader().readLine()) != null) {
6 postData += str;
7 }
8
9 //deal post data and response back data as XML format
10 out.println(“<root> <Node1>”+postData +” </Node1> </root>”);
11 %>
12
2 //取得提交的參數
3 String postData = “”;
4 String str;
5 While ( (str = request.getReader().readLine()) != null) {
6 postData += str;
7 }
8
9 //deal post data and response back data as XML format
10 out.println(“<root> <Node1>”+postData +” </Node1> </root>”);
11 %>
12
參考資料
MSDN MSXML SDK http://msdn.microsoft.com/en-us/library/ms759148(VS.85).aspx
MSXML6.0 下載鏈接
http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en本文只是拋磚引玉,如果大家更好意見和建議,歡迎大家提出來分享。
本文示例下載
Good Luck!
Yours Matthew!