一、整體方案介紹
說(shuō)明: VB客戶端使用msxml.dll組件,創(chuàng)建XMLHTTP對(duì)象,通過(guò)該對(duì)象以HTTP方式訪問(wèn)WebServer請(qǐng)求,提交數(shù)據(jù)并取得返回的數(shù)據(jù)結(jié)果
二、如何使用MSXML組件進(jìn)行開(kāi)發(fā)
a) MSXML組件引入項(xiàng)目
MSXML組件引入項(xiàng)目比較簡(jiǎn)單,方法如下圖所示:
注:建議使用MSXML v6.0版本,如果本地沒(méi)有可上官網(wǎng)上下載。
客戶端代碼編寫(xiě)
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提交數(shù)據(jù)</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數(shù)據(jù)格式
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提交數(shù)據(jù)</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數(shù)據(jù)格式
20 responseText = xmlhttp.responseText
21
22 Set xmlhttp = Nothing
23
服務(wù)器代碼編寫(xiě)(Jsp示例)
1 <%
2 //取得提交的參數(shù)
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 //取得提交的參數(shù)
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本文只是拋磚引玉,如果大家更好意見(jiàn)和建議,歡迎大家提出來(lái)分享。
本文示例下載
Good Luck!
Yours Matthew!